---
title: "Replication File (Appendix): The Limits of Public Support for Fiscal Consolidation: Survey Evidence from Great Britain"
author: "Björn Bremer, Charlotte Cavaille, Lisanne de Blok, Catherine de Vries"
date: "February 3, 2026"
output:
  bookdown::html_document2:
    keep_tex: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(message = FALSE)
knitr::opts_chunk$set(warning = FALSE)
```

```{r, include=FALSE}
rm(list = ls())
set.seed(1234567)

# List of packages needed
packages <- c("tidyverse",
              "haven",
              "bookdown",
              "stargazer",
              "gridExtra",
              "ggpubr",
              "margins",
              "coefplot",
              "modelsummary",
              "xtable",
              "estimatr",
              "kableExtra",
              "ltm", 
              "patchwork",
              "ggrepel",
              "tinytable"
)

# Function to check if packages are installed and install if needed
package_check <- function(pkg){
  if (!require(pkg, character.only = TRUE)) {
    install.packages(pkg, dependencies = TRUE)
    library(pkg, character.only = TRUE)
  }
}

# Apply function to each package
invisible(sapply(packages, package_check))

# Create directories to save data
if (!dir.exists("data")) {
  dir.create("data")
}

# Create directories to save figures
if (!dir.exists("figures")) {
  dir.create("figures")
}

```

# Load data from all waves

```{r, results = 'asis', message=F, echo=FALSE}
## load all data

# load and clean debt data
debt_data <- read_csv("clean_general_gov_debt.csv") %>%
  dplyr::select(-1) %>%  # Drop first column (v1)
  rename(Debt = Value) %>%
  mutate(Debt = ifelse(Debt == "NA", NA, Debt),
         Debt = as.numeric(Debt)) %>%
  filter(Year > 1980)

# load and clean interest rates data
interest_data <- read_csv("clean_interest_rates.csv") %>%
  dplyr::select(-1) %>%  # Drop first column (v1)
  rename(Interest = value) %>%
  rename(Year = year) %>%
  mutate(Interest = ifelse(Interest == "NA", NA, Interest),
         Interest = as.numeric(Interest)) %>%
  filter(Year > 1980)

load("data/data_processed_w1.RData")
load("data/data_processed_w2.RData")
load("data/data_processed_w2_w3.RData")
```

# Appendix A

## Figure A.1: Results from our cross-national pilot

```{r, results = 'asis', message=F, echo=FALSE}
df <- readxl::read_xlsx("data_Bertelsmann_2022-04-01_12-18.xlsx")

df <- df[which(df$country_code=="BE" |df$country_code=="DE" |df$country_code=="ES" |df$country_code=="FR" |df$country_code=="GB" |df$country_code=="IT" |df$country_code=="NL" |df$country_code=="PL"),]

# recode problem seriousness debt
df$problem_debt <- ifelse(df$public_debt_serious_problem==1, "Agree", ifelse(df$public_debt_serious_problem==2, "Somewhat agree", ifelse(df$public_debt_serious_problem==3, "Somewhat disagree", ifelse(df$public_debt_serious_problem==4, "Disagree", NA))))

# recode problem seriousness climate change
df$problem_climate <- ifelse(df$climate_change_serious_problem==1, "Agree", ifelse(df$climate_change_serious_problem==2, "Somewhat agree", ifelse(df$climate_change_serious_problem==3, "Somewhat disagree", ifelse(df$climate_change_serious_problem==4, "Disagree", NA))))

# plot the seriousness graph: debt
df_problem <- df %>% 
  mutate(problem_debt = factor(problem_debt, levels = c("Agree", "Somewhat agree", "Somewhat disagree", "Disagree"))) %>% group_by(country_code, problem_debt)  %>% 
  summarise(n = n()) %>% 
  mutate(proportion = n/ sum(n)) 

plot_debt_serious <-
      ggplot(aes(fill=problem_debt, y=proportion, x=country_code), data=df_problem) + 
      geom_bar(position="fill", stat="identity") + labs(y = "Share", x = "Country") + 
      theme_bw() + scale_fill_manual(breaks=c("Agree", "Somewhat agree", "Somewhat disagree", "Disagree"), values=c("grey15","grey30", "grey60", "grey90")) +
      guides(fill=guide_legend(title="")) + 
      geom_text(aes(label = round(proportion,3)),size = 2.5, color="white", position = position_stack(vjust = 0.5)) +
      ggtitle("Public Debt") +
      theme(plot.title = element_text(face = "bold"))
plot_debt_serious

# plot the seriousness graph: climate change
df_problem_cc <- df %>%
      mutate(problem_climate = factor(problem_climate, levels = c("Agree", "Somewhat agree", "Somewhat disagree", "Disagree"))) %>% group_by(country_code, problem_climate) %>% 
  summarise(n = n()) %>% 
  mutate(proportion = n/ sum(n))

plot_cc_serious <-
      ggplot(aes(fill=problem_climate, y=proportion, x=country_code), data=df_problem_cc) + 
      geom_bar(position="fill", stat="identity") + labs(y = "Share", x = "Country") + 
      theme_bw() + scale_fill_manual(breaks=c("Agree", "Somewhat agree", "Somewhat disagree", "Disagree"), values=c("grey15","grey30", "grey60", "grey90")) +
      guides(fill=guide_legend(title="")) + 
      geom_text(aes(label = round(proportion,3)),size = 2.5, color="white", position = position_stack(vjust = 0.5)) +
      ggtitle("Climate Change") +
      theme(plot.title = element_text(face = "bold"))
plot_cc_serious

plot_compare <- ggarrange(plot_debt_serious, plot_cc_serious, common.legend = T, legend = "bottom", nrow = 1, ncol=2)
plot_compare

ggsave(plot_compare, width = 20, height = 10, units = c("cm"), file ="appendix/FigureA1.pdf")

```

## Figure A.3: Manipulation check

```{r, results = 'asis', message=F, echo=FALSE}
# Manipulation check
debt_w1$MC_S_passed <- ifelse(debt_w1$treat_w1==2 &debt_w1$MC_S_w1==0, "Failed", ifelse(debt_w1$treat_w1==2 &debt_w1$MC_S_w1==1, "Passed", ifelse(debt_w1$treat_w1==1, "Control", NA)))
debt_w1$MC_US_passed <- ifelse(debt_w1$treat_w1==3 &debt_w1$MC_US_w1==0, "Failed", ifelse(debt_w1$treat_w1==3 &debt_w1$MC_US_w1==1, "Passed", ifelse(debt_w1$treat_w1==1, "Control", NA)))
debt_w1$MC_passed <- debt_w1$MC_S_passed
debt_w1$MC_passed <- ifelse(is.na(debt_w1$MC_passed), debt_w1$MC_US_passed, debt_w1$MC_passed)

debt_w2$MC_S_passed <- ifelse(debt_w2$treat_w2==2 &debt_w2$MC_S_w2==0, "Failed", ifelse(debt_w2$treat_w2==2 &debt_w2$MC_S_w2==1, "Passed", ifelse(debt_w2$treat_w2==1, "Control", NA)))
debt_w2$MC_US_passed <- ifelse(debt_w2$treat_w2==3 &debt_w2$MC_US_w2==0, "Failed", ifelse(debt_w2$treat_w2==3 &debt_w2$MC_US_w2==1, "Passed", ifelse(debt_w2$treat_w2==1, "Control", NA)))
debt_w2$MC_passed <- debt_w2$MC_S_passed
debt_w2$MC_passed <- ifelse(is.na(debt_w2$MC_passed), debt_w2$MC_US_passed, debt_w2$MC_passed)

gg_mc_sust_w1 <-debt_w1[which(debt_w1$treat_w1==2),] %>%
  group_by(MC_passed) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% ggplot(aes(y = freq, x=MC_passed)) +  
  geom_bar(stat="identity") + 
  scale_y_continuous(breaks = c(0.0, 0.2, 0.4,  0.6, 0.8, 1)) + 
  ylab("Share") + xlab("") + theme_bw() + geom_text(aes(label = round(freq,3)),size = 3, color="white", position = position_stack(vjust = 0.5))

gg_mc_unsust_w1 <-debt_w1[which(debt_w1$treat_w1==3),] %>%
  group_by(MC_passed) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% ggplot(aes(y = freq, x=MC_passed)) +  
  geom_bar(stat="identity") + 
  scale_y_continuous(breaks = c(0.0, 0.2, 0.4,  0.6, 0.8, 1)) + 
  ylab("Share") + xlab("") + theme_bw() + geom_text(aes(label = round(freq,3)),size = 3, color="white", position = position_stack(vjust = 0.5))

gg_mc_sust_w2 <-debt_w2[which(debt_w2$treat_w2==2 & !is.na(debt_w2$MC_passed)),] %>%
  group_by(MC_passed) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% ggplot(aes(y = freq, x=MC_passed)) +  
  geom_bar(stat="identity") + 
  scale_y_continuous(breaks = c(0.0, 0.2, 0.4,  0.6, 0.8, 1)) + 
  ylab("Share") + xlab("") + theme_bw() + geom_text(aes(label = round(freq,3)),size = 3, color="white", position = position_stack(vjust = 0.5))

gg_mc_unsust_w2 <-debt_w2[which(debt_w2$treat_w2==3),] %>%
  group_by(MC_passed) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% ggplot(aes(y = freq, x=MC_passed)) +  
  geom_bar(stat="identity") + 
  scale_y_continuous(breaks = c(0.0, 0.2, 0.4,  0.6, 0.8, 1)) + 
  ylab("Share") + xlab("") + theme_bw() + geom_text(aes(label = round(freq,3)),size = 3, color="white", position = position_stack(vjust = 0.5))

manipulation_check_graph <- ggarrange(gg_mc_sust_w1, gg_mc_sust_w2, gg_mc_unsust_w1, gg_mc_unsust_w2, ncol = 2, nrow = 2, labels = c( "Survey 1", "Survey 2"), hjust = c(-2.5, -2.5), vjust = c(0.1, 0.1), font.label = list(size = 12, color = "black", face = "bold", family = NULL)) +  theme(plot.margin = margin(0.4,0.2,0,0.0, "cm"))
manipulation_check_graph <- annotate_figure(manipulation_check_graph, left = text_grob("  Unsustainable                           Sustainable", rot = 90, face = "bold"))
manipulation_check_graph
ggsave(manipulation_check_graph, width = 20, height = 12, units = c("cm"), file ="appendix/FigureA3.pdf")
```

## Figure A.4: Rating of Video

```{r, results = 'asis', message=F, echo=FALSE}
# How do respondents rate the two videos? 
debt_w1$rating1_S_w1 <- as.numeric(debt_w1$rating1_S_w1)
debt_w1$rating1_US_w1 <- as.numeric(debt_w1$rating1_US_w1)
debt_w2$rating1_S_w2 <- as.numeric(debt_w2$rating1_S_w2)
debt_w2$rating1_US_w2 <- as.numeric(debt_w2$rating1_US_w2)

gg_rate1_sust_w1 <-debt_w1[which(debt_w1$treat_w1==2),] %>%
  group_by(rating1_S_w1) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% ggplot(aes(y = freq, x=rating1_S_w1)) +  
  geom_bar(stat="identity") + 
  scale_y_continuous(breaks = c(0.0, 0.2, 0.4,  0.6, 0.8, 1)) + 
  ylab("Share") + scale_x_continuous("", breaks=c(1,2,3), labels = c("Not instructive", "Somewhat", "Very instructive")) + theme_bw() + geom_text(aes(label = round(freq,3)),size = 3, color="white", position = position_stack(vjust = 0.5))

gg_rate1_unsust_w1 <-debt_w1[which(debt_w1$treat_w1==3& !is.na(debt_w1$rating1_US_w1)),] %>%
  group_by(rating1_US_w1) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% ggplot(aes(y = freq, x=rating1_US_w1)) +  
  geom_bar(stat="identity") + 
  scale_y_continuous(breaks = c(0.0, 0.2, 0.4,  0.6, 0.8, 1)) + 
  ylab("Share") + scale_x_continuous("",breaks=c(1,2,3), labels = c("Not instructive", "Somewhat", "Very instructive")) + theme_bw() + geom_text(aes(label = round(freq,3)),size = 3, color="white", position = position_stack(vjust = 0.5))

gg_rate1_sust_w2 <-debt_w2[which(debt_w2$treat_w2==2 & !is.na(debt_w2$rating1_S_w2)),] %>%
  group_by(rating1_S_w2) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% ggplot(aes(y = freq, x=rating1_S_w2)) +  
  geom_bar(stat="identity") + 
  scale_y_continuous(breaks = c(0.0, 0.2, 0.4,  0.6, 0.8, 1)) + 
  ylab("Share") + scale_x_continuous("",breaks=c(1,2,3), labels = c("Not instructive", "Somewhat", "Very instructive")) + theme_bw() + geom_text(aes(label = round(freq,3)),size = 3, color="white", position = position_stack(vjust = 0.5))

gg_rate1_unsust_w2 <-debt_w2[which(debt_w2$treat_w2==3),] %>%
  group_by(rating1_US_w2) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% ggplot(aes(y = freq, x=rating1_US_w2)) +  
  geom_bar(stat="identity") + 
  scale_y_continuous(breaks = c(0.0, 0.2, 0.4,  0.6, 0.8, 1)) + 
  ylab("Share") + scale_x_continuous("",breaks=c(1,2,3), labels = c("Not instructive", "Somewhat", "Very instructive")) + theme_bw() + geom_text(aes(label = round(freq,3)),size = 3, color="white", position = position_stack(vjust = 0.5))

rating1_graph <- ggarrange(gg_rate1_sust_w1, gg_rate1_sust_w2, gg_rate1_unsust_w1, gg_rate1_unsust_w2, ncol = 2, nrow = 2, labels = c( "Survey 1", "Survey 2"), hjust = c(-2.5, -2.5), vjust = c(0.1, 0.1), font.label = list(size = 12, color = "black", face = "bold", family = NULL)) +  theme(plot.margin = margin(0.4,0.2,0,0.0, "cm"))
rating1_graph <- annotate_figure(rating1_graph, left = text_grob("  Unsustainable                           Sustainable", rot = 90, face = "bold"))
rating1_graph
ggsave(rating1_graph, width = 20, height = 12, units = c("cm"), file ="appendix/FigureA4.pdf")
```

## Figure A.5: Share of respondents who would recommend the video to a friend

```{r, results = 'asis', message=F, echo=FALSE}
# Would they recommend them to a friend or not? 
debt_w1$rating2_S_w1 <- as.numeric(debt_w1$rating2_S_w1)
debt_w1$rating2_US_w1 <- as.numeric(debt_w1$rating2_US_w1)
debt_w2$rating2_S_w2 <- as.numeric(debt_w2$rating2_S_w2)
debt_w2$rating2_US_w2 <- as.numeric(debt_w2$rating2_US_w2)

gg_rate2_sust_w1 <-debt_w1[which(debt_w1$treat_w1==2),] %>%
  group_by(rating2_S_w1) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% ggplot(aes(y = freq, x=rating2_S_w1)) +  
  geom_bar(stat="identity") + 
  scale_y_continuous(breaks = c(0.0, 0.2, 0.4,  0.6, 0.8, 1)) + 
  ylab("Share") + scale_x_continuous("", breaks=c(1,2,3), labels = c("No", "Maybe", "Yes")) + theme_bw() + geom_text(aes(label = round(freq,3)),size = 3, color="white", position = position_stack(vjust = 0.5))

gg_rate2_unsust_w1 <-debt_w1[which(debt_w1$treat_w1==3& !is.na(debt_w1$rating2_US_w1)),] %>%
  group_by(rating2_US_w1) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% ggplot(aes(y = freq, x=rating2_US_w1)) +  
  geom_bar(stat="identity") + 
  scale_y_continuous(breaks = c(0.0, 0.2, 0.4,  0.6, 0.8, 1)) + 
  ylab("Share") + scale_x_continuous("",breaks=c(1,2,3), labels = c("No", "Maybe", "Yes")) + theme_bw() + geom_text(aes(label = round(freq,3)),size = 3, color="white", position = position_stack(vjust = 0.5))

gg_rate2_sust_w2 <-debt_w2[which(debt_w2$treat_w2==2 & !is.na(debt_w2$rating2_S_w2)),] %>%
  group_by(rating2_S_w2) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% ggplot(aes(y = freq, x=rating2_S_w2)) +  
  geom_bar(stat="identity") + 
  scale_y_continuous(breaks = c(0.0, 0.2, 0.4,  0.6, 0.8, 1)) + 
  ylab("Share") + scale_x_continuous("",breaks=c(1,2,3), labels = c("No", "Maybe", "Yes")) + theme_bw() + geom_text(aes(label = round(freq,3)),size = 3, color="white", position = position_stack(vjust = 0.5))

gg_rate2_unsust_w2 <-debt_w2[which(debt_w2$treat_w2==3),] %>%
  group_by(rating2_US_w2) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% ggplot(aes(y = freq, x=rating2_US_w2)) +  
  geom_bar(stat="identity") + 
  scale_y_continuous(breaks = c(0.0, 0.2, 0.4,  0.6, 0.8, 1)) + 
  ylab("Share") + scale_x_continuous("",breaks=c(1,2,3), labels = c("No", "Maybe", "Yes")) + theme_bw() + geom_text(aes(label = round(freq,3)),size = 3, color="white", position = position_stack(vjust = 0.5))

rating2_graph <- ggarrange(gg_rate2_sust_w1, gg_rate2_sust_w2, gg_rate2_unsust_w1, gg_rate2_unsust_w2, ncol = 2, nrow = 2, labels = c( "Survey 1", "Survey 2"), hjust = c(-2.5, -2.5), vjust = c(0.1, 0.1), font.label = list(size = 12, color = "black", face = "bold", family = NULL)) +  theme(plot.margin = margin(0.4,0.2,0,0.0, "cm"))
rating2_graph <- annotate_figure(rating2_graph, left = text_grob("  Unsustainable                           Sustainable", rot = 90, face = "bold"))
rating2_graph
ggsave(rating2_graph, width = 20, height = 12, units = c("cm"), file ="appendix/FigureA5.pdf")
```

## Table A.3: Balance checks: Survey 1 and Survey 2

```{r, results = 'asis', message=F, echo=FALSE}
# Survey 1
df_w1_summary <- debt_w1 %>%
mutate(treat_labels = ifelse(treat_w1==2, "Sustainable", ifelse(treat_w1==3, "Unsustainable", ifelse(treat_w1==1, "Control", NA))),
         edu_rec_w1_num = ifelse(edu_rec_w1=="Low", 0, ifelse(edu_rec_w1=="Middle", 1,     ifelse(edu_rec_w1=="High", 2, NA))),
         income_cat_w1_num = ifelse(income_cat_w1=="Low", 0, ifelse(income_cat_w1=="Middle", 1,     ifelse(income_cat_w1=="High", 2, NA))),
         cert_debt_rec_w1_num = ifelse(cert_debt_rec_w1=="Not a serious problem", 0, ifelse(cert_debt_rec_w1=="Uncertain", 1,     ifelse(cert_debt_rec_w1=="Serious problem", 2, NA))),
         think_debt_rec_w1_num = ifelse(think_debt_rec_w1=="Never", 0, ifelse(think_debt_rec_w1=="A little", 1,     ifelse(think_debt_rec_w1=="Moderate amount", 2, ifelse(think_debt_rec_w1=="A great deal", 3,NA))))) %>% 
  dplyr::select(Treatment = treat_labels,
         `Age` = age_w1,
         `Female` = gender_rec_w1,
         `Education` = edu_rec_w1_num,
         `Left-right placement` = party_w1,
         `Income` = income_cat_w1_num,
         `Prior concern` = cert_debt_rec_w1_num,
        `Thought about debt` = think_debt_rec_w1_num)

# Version with difference in means test
control_sustainable_w1 <- datasummary_balance(~Treatment,
                    data = df_w1_summary[which(df_w1_summary$Treatment!="Sustainable"),], modelsummary_format_numeric_latex = "plain", dinm = T, dinm_statistic="p.value", stars=T, escape = FALSE, output = "data.frame")
control_unsustainable_w1 <- datasummary_balance(~Treatment,
                    data = df_w1_summary[which(df_w1_summary$Treatment!="Unsustainable"),], modelsummary_format_numeric_latex = "plain", dinm = T, dinm_statistic="p.value", stars=T, escape = FALSE, output = "data.frame")
balance_test_survey1 <- cbind(control_sustainable_w1, control_unsustainable_w1)
balance_test_survey1 <- balance_test_survey1[-c(9:12)]
balance_test_survey1 %>% 
  kbl(caption = "Balance check across treatment groups in survey 1", booktabs = T, escape = FALSE,linesep = "", format = "latex") %>%
column_spec(3:4, width = "1.5cm") %>%
  column_spec(5:6, width = "2cm") %>%
    column_spec(7, width = "1.2cm") %>%
      column_spec(8, width = "0.6cm") %>%
  column_spec(9:10, width = "1.5cm") %>% 
    column_spec(11, width = "1.2cm") %>%
      column_spec(12, width = "0.6cm") %>%
            kable_styling(font_size = 10) %>% 
  save_kable("appendix/TableA3_w1.tex")

# Survey 2
df_w2_summary <- debt_w2_w3 %>%
  mutate(treat_labels = ifelse(treat_w2==2, "Sustainable", ifelse(treat_w2==3, "Unsustainable", ifelse(treat_w2==1, "Control", NA))),
         edu_rec_w2_num = ifelse(edu_rec_w2=="Low", 0, ifelse(edu_rec_w2=="Middle", 1,     ifelse(edu_rec_w2=="High", 2, NA))),
         income_cat_w2_num = ifelse(income_cat_w2=="Low", 0, ifelse(income_cat_w2=="Middle", 1,     ifelse(income_cat_w2=="High", 2, NA))),
         cert_debt_rec_w2_num = ifelse(cert_debt_rec_w2=="Not a serious problem", 0, ifelse(cert_debt_rec_w2=="Uncertain", 1,     ifelse(cert_debt_rec_w2=="Serious problem", 2, NA))),
         think_debt_rec_w2_num = ifelse(think_debt_rec_w2=="Never", 0, ifelse(think_debt_rec_w2=="A little", 1,     ifelse(think_debt_rec_w2=="Moderate amount", 2, ifelse(think_debt_rec_w2=="A great deal", 3,NA))))) %>% 
  dplyr::select(Treatment = treat_labels,
         `Age` = age_w2,
         `Female` = gender_rec_w2,
         `Education` = edu_rec_w2_num,
         `Left-right placement` = party_w2,
         `Income` = income_cat_w2_num,
         `Prior concern` = cert_debt_rec_w2_num,
        `Thought about debt` = think_debt_rec_w2_num)

# Version with difference in means test
control_sustainable_w2 <- datasummary_balance(~Treatment,
                    data = df_w2_summary[which(df_w2_summary$Treatment!="Sustainable"),],
                    modelsummary_format_numeric_latex = "plain", dinm = T, dinm_statistic="p.value", stars=T, escape = FALSE, output = "data.frame")
control_unsustainable_w2 <- datasummary_balance(~Treatment,
                    data = df_w2_summary[which(df_w2_summary$Treatment!="Unsustainable"),],
                    modelsummary_format_numeric_latex = "plain", dinm = T, dinm_statistic="p.value", stars=T, escape = FALSE, output = "data.frame")
balance_test_survey2 <- cbind(control_sustainable_w2, control_unsustainable_w2)
balance_test_survey2 <- balance_test_survey2[-c(9:12)]
balance_test_survey2 %>% 
  kbl(caption = "Balance check across treatment groups in survey 2", booktabs = T, escape = FALSE,linesep = "", format = "latex") %>%
  column_spec(3:4, width = "1.5cm") %>%
  column_spec(5:6, width = "2cm") %>%
    column_spec(7, width = "1.2cm") %>%
      column_spec(8, width = "0.6cm") %>%
  column_spec(9:10, width = "1.5cm") %>% 
    column_spec(11, width = "1.2cm") %>%
      column_spec(12, width = "0.6cm") %>%
      kable_styling(font_size = 10) %>% 
  save_kable("appendix/TableA3_w2.tex")
```

## Table A.4: Characteristics of people who dropped out in the treatment vs. the control group 

### Wave 1

```{r, include=FALSE}
## clean the data
debt_w1_all<- read.csv("Debt & Preferences - New version_February 8, 2022_07.44.csv", colClasses = c("character"), sep = ",")
debt_w1_all <- debt_w1_all[-c(1:2),] # remove unnecessary columns
debt_w1_all <- debt_w1_all[which(debt_w1_all$treat!="9999"),]

# change the variable names
names(debt_w1_all) <- gsub(x = names(debt_w1_all), pattern = "\\.", replacement = "")  

# creating dummy for speeders
debt_w1_all$duration <- as.numeric(debt_w1_all$Durationinseconds)
debt_w1_all$speeder <- ifelse(debt_w1_all$duration<230 & debt_w1_all$treat==1 |debt_w1_all$duration<303 & debt_w1_all$treat==2 |debt_w1_all$duration<309 & debt_w1_all$treat==3, 1, 0)
table(debt_w1_all$speeder)

# create a measure for whether respondents passed the sound check and the attention check and did not speed
debt_w1_all$Finished <- as.numeric(debt_w1_all$Finished)
debt_w1_all$soundC <- as.numeric(debt_w1_all$soundC)
debt_w1_all$AC <- as.numeric(debt_w1_all$AC)
debt_w1_all$SC_passed <- ifelse(debt_w1_all$soundC==3, 1, 0)
debt_w1_all$AC_passed <- ifelse(debt_w1_all$AC==8, 1, 0)
debt_w1_all$check <- ifelse(debt_w1_all$speeder==0 & debt_w1_all$soundC==3 & debt_w1_all$AC==8, 1, 0)
unique(debt_w1_all$check)
table(debt_w1_all$treat, debt_w1_all$check)
```

```{r, include=FALSE}
## recode control variables
debt_w1_all$age <-2021-as.numeric(debt_w1_all$yrbrn)
debt_w1_all$age_qua <- poly(debt_w1_all$age,2)
debt_w1_all$age_rec <- ifelse(debt_w1_all$age<35, "Up to 35", ifelse(debt_w1_all$age>=35 & debt_w1_all$age<51, "35-50", ifelse(debt_w1_all$age>=51 & debt_w1_all$age<65, "51-65", ifelse(debt_w1_all$age>=65, "65+", NA))))
# gender
debt_w1_all$gender_rec <- ifelse(debt_w1_all$gender==1, 1, ifelse(debt_w1_all$gender==2 |debt_w1_all$gender==3, 0, NA))
debt_w1_all$gender_rec2 <- ifelse(debt_w1_all$gender==1, "Female", ifelse(debt_w1_all$gender==2 |debt_w1_all$gender==3, "Male", NA))

#education
debt_w1_all$educ <- as.numeric(debt_w1_all$educ)
debt_w1_all$edu_rec <- ifelse(debt_w1_all$educ==1 | debt_w1_all$educ==2 | debt_w1_all$educ ==3, 1, # Below A-Levels
                              ifelse(debt_w1_all$educ==4, 2, # A-Levels
                                     ifelse(debt_w1_all$educ==5 | debt_w1_all$educ==6, 3, # Foundation Degree, etc
                                            ifelse(debt_w1_all$educ==7, 4, # BA
                                                   ifelse(debt_w1_all$educ==8 |debt_w1_all$educ==9, 5, NA))))) #MA plus
table(debt_w1_all$edu_rec)
debt_w1_all$edu_rec2 <- ifelse(debt_w1_all$edu_rec>=3, "High",  
                        ifelse(debt_w1_all$edu_rec==2, "Middle",
                               ifelse(debt_w1_all$edu_rec==1, "Low", debt_w1_all$edu_rec)))

#employment (this needs to be edited)
debt_w1_all$emp <- as.numeric(debt_w1_all$emp)
debt_w1_all$emp_rec <- ifelse(debt_w1_all$emp==10 | debt_w1_all$emp==11 | debt_w1_all$emp==16, "Employed or student",
                       ifelse(debt_w1_all$emp==12 | debt_w1_all$emp==13, "Unemployed", 
                              ifelse(debt_w1_all$emp==15, "Retired", 
                                     ifelse(debt_w1_all$emp==14 | debt_w1_all$emp ==17 | debt_w1_all$emp == 18, "Out of work force", NA))))

#income
debt_w1_all$income <- debt_w1_all$hhinc_w
debt_w1_all$income <- ifelse(debt_w1_all$income=="", debt_w1_all$hhinc_m, debt_w1_all$income)
debt_w1_all$income <- ifelse(debt_w1_all$income=="", debt_w1_all$hhinc_y, debt_w1_all$income)
debt_w1_all$income <- ifelse(debt_w1_all$income=="" | debt_w1_all$income=="99" | debt_w1_all$income=="88", NA, debt_w1_all$income)
debt_w1_all$income <- as.numeric(debt_w1_all$income)
debt_w1_all$income_cat <- ifelse(debt_w1_all$income<=3, "Low",
                          ifelse(debt_w1_all$income==4 |debt_w1_all$income==5 |debt_w1_all$income==6 |debt_w1_all$income==7, "Middle",
                                 ifelse(debt_w1_all$income>=8, "High", NA)))

# political variables / mediators vote
debt_w1_all$vote_part1 <- as.numeric(debt_w1_all$vote_part1)
debt_w1_all$vote_part2 <- as.numeric(debt_w1_all$vote_part2)

debt_w1_all$party_1 <- ifelse(debt_w1_all$vote_part1 == 1 | debt_w1_all$vote_part1 == 7 | debt_w1_all$vote_part1 == 8, "Right-wing",
                       ifelse(debt_w1_all$vote_part1 == 2 | debt_w1_all$vote_part1 == 4 | debt_w1_all$vote_part1 == 5 | debt_w1_all$vote_part1 == 6, "Left-wing",
                              ifelse(debt_w1_all$vote_par1t1 == 3, "Lib Dems",
                                     ifelse(debt_w1_all$vote_part1 == 9 | debt_w1_all$vote_part1 == 88, "Other", NA))))

debt_w1_all$party_2 <- ifelse(debt_w1_all$vote_part2 == 1 | debt_w1_all$vote_part2 == 5 | debt_w1_all$vote_part2 == 7 | debt_w1_all$vote_part2 == 8, "Right-wing",
                       ifelse(debt_w1_all$vote_part2 == 2 | debt_w1_all$vote_part2 == 4 | debt_w1_all$vote_part2 == 6, "Left-wing",
                              ifelse(debt_w1_all$vote_part2 == 3, "Lib Dems",
                                     ifelse(debt_w1_all$vote_part2 == 9 | debt_w1_all$vote_part2 == 88, "Other", NA))))
debt_w1_all$party <- debt_w1_all$party_1
debt_w1_all$party <- ifelse(debt_w1_all$party=="" | is.na(debt_w1_all$party), debt_w1_all$party_2, debt_w1_all$party)

# certainty on debt
debt_w1_all$cert_debt <- debt_w1_all$cert_debt_V1_1 
debt_w1_all$cert_debt <- ifelse(debt_w1_all$cert_debt =="", debt_w1_all$cert_debt_V1_2, debt_w1_all$cert_debt)
debt_w1_all$cert_debt <- ifelse(debt_w1_all$cert_debt =="", debt_w1_all$cert_debt_V2_3, debt_w1_all$cert_debt)
debt_w1_all$cert_debt <- ifelse(debt_w1_all$cert_debt =="", debt_w1_all$cert_debt_V2_4, debt_w1_all$cert_debt)
debt_w1_all$cert_debt <- as.numeric(debt_w1_all$cert_debt)
table(debt_w1_all$cert_debt)
debt_w1_all$cert_debt_rec <- ifelse(debt_w1_all$cert_debt==3, "Serious problem",
                             ifelse(debt_w1_all$cert_debt==2, "Uncertain",
                                    ifelse(debt_w1_all$cert_debt==1, "Not a serious problem", NA)))
debt_w1_all$cert_debt_rec <- as.factor(debt_w1_all$cert_debt_rec)

# having thought about debt
debt_w1_all$think_debt <- debt_w1_all$think_debt_V1_1 
debt_w1_all$think_debt <- ifelse(debt_w1_all$think_debt =="", debt_w1_all$think_debt_V2_2, debt_w1_all$think_debt)
debt_w1_all$think_debt <- ifelse(debt_w1_all$think_debt =="", debt_w1_all$think_debt_V1_3, debt_w1_all$think_debt)
debt_w1_all$think_debt <- ifelse(debt_w1_all$think_debt =="", debt_w1_all$think_debt_V2_4, debt_w1_all$think_debt)
debt_w1_all$think_debt <- as.numeric(debt_w1_all$think_debt)
table(debt_w1_all$think_debt)
debt_w1_all$think_debt_rec <- ifelse(debt_w1_all$think_debt==4, "A great deal",
                          ifelse(debt_w1_all$think_debt==3, "Moderate amount",
                             ifelse(debt_w1_all$think_debt==2, "A little",
                                    ifelse(debt_w1_all$think_debt==1, "Never", NA))))
debt_w1_all$think_debt_rec <- as.factor(debt_w1_all$think_debt_rec)

# concern over debt
debt_w1_all$debt_pre <- debt_w1_all$MC_debt_V1_1 
debt_w1_all$debt_pre <- ifelse(debt_w1_all$debt_pre =="", debt_w1_all$MC_debt_V1_2, debt_w1_all$debt_pre)
debt_w1_all$debt_pre <- ifelse(debt_w1_all$debt_pre =="", debt_w1_all$MC_debt_V2_3, debt_w1_all$debt_pre)
debt_w1_all$debt_pre <- ifelse(debt_w1_all$debt_pre =="", debt_w1_all$MC_debt_V2_4, debt_w1_all$debt_pre)
debt_w1_all$debt_pre <- as.numeric(debt_w1_all$debt_pre)
table(debt_w1_all$debt_pre)
```

```{r, results = 'asis', message=F, echo=FALSE}
debt_w1_all <- debt_w1_all[which(duplicated(debt_w1_all$respid)==F),] # remove duplicates

lm.1_w1_all <- lm(Finished ~ treat +  as.factor(debt_pre) + as.factor(block), data = debt_w1_all)
lm.2_w1_all <- lm(Finished ~ treat + age + gender_rec2 + edu_rec2 + party + income_cat +cert_debt_rec + think_debt_rec + emp_rec+ as.factor(debt_pre) + as.factor(block), data = debt_w1_all)

#modelsummary(list("M1" = lm.1_w1_all, "M2" = lm.2_w1_all), stars = TRUE, title="Regression table: Determinants of finishing survey 1", coef_rename = c("treat2" = "Sustainable", "treat3" = "Unsustainable", "age" = "Age", "gender_rec2Male"= "Male (ref.: female)", "partyLib Dems" = "Lib Dems (ref.: left-wing)", "partyOther"= "Other parties (ref.: left-wing)", "partyRight-wing"="Right-wing (ref.: left-wing)", "income_catLow"="Low income (ref.: high)", "income_catMiddle"="Middle income (ref.: high)", "edu_rec2Low"="Low education (ref.: high)", "edu_rec2Middle"="Middle education (ref.: high)", "cert_debt_recSerious problem"= "Debt serious problem (ref.: not serious)", "cert_debt_recUncertain"= "Debt uncertain (ref.: not serious)", "think_debt_recA little"=" Thought about debt a little (ref.: a great deal)", "think_debt_recModerate amount"="Thought about debt moderate amount (ref.: a great deal)", "think_debt_recNever"="Thought never about debt (ref.: a great deal)", "emp_recOut of work force"="Out of work force (ref.: employed or student)", "emp_recRetired"="Retired (ref.: employed or student)", "emp_recUnemployed"="Unemployed (ref.: employed or student)"), coef_omit = "as.factor", output = 'tables/dropout_regression_survey1.tex')

df_summary <- debt_w1_all[which(debt_w1_all$Finished!=1),] %>%
mutate(Treatment = ifelse(treat==1, "Control", ifelse(treat==2, "Sustainable", ifelse(treat==3, "Unsustainable", NA))),
         edu_rec2_num = ifelse(edu_rec2=="Low", 0, ifelse(edu_rec2=="Middle", 1,     ifelse(edu_rec2=="High", 2, NA))),
         income_cat_num = ifelse(income_cat=="Low", 0, ifelse(income_cat=="Middle", 1,     ifelse(income_cat=="High", 2, NA))),
         cert_debt_rec_num = ifelse(cert_debt_rec=="Not a serious problem", 0, ifelse(cert_debt_rec=="Uncertain", 1,     ifelse(cert_debt_rec=="Serious problem", 2, NA))),
         think_debt_rec_num = ifelse(think_debt_rec=="Never", 0, ifelse(think_debt_rec=="A little", 1,     ifelse(think_debt_rec=="Moderate amount", 2, ifelse(think_debt_rec=="A great deal", 3,NA))))) %>% 
  dplyr::select(Treatment,
         `Age` = age,
         `Female` = gender_rec2,
         `Education` = edu_rec2_num,
         `Left-right placement` = party,
         `Income` = income_cat_num,
         `Prior concern` = cert_debt_rec_num,
        `Thought about debt` = think_debt_rec_num)

control_sustainable_w1 <- datasummary_balance(~Treatment,
                    data = df_summary[which(df_summary$Treatment!="Sustainable"),], modelsummary_format_numeric_latex = "plain", dinm = T, dinm_statistic="p.value", stars=T, escape = FALSE, output = "data.frame")
control_unsustainable_w1 <- datasummary_balance(~Treatment,
                    data = df_summary[which(df_summary$Treatment!="Unsustainable"),], modelsummary_format_numeric_latex = "plain", dinm = T, dinm_statistic="p.value", stars=T, escape = FALSE, output = "data.frame")
new_row <- c("", "Lib Dems", "0", "0.0", "0", "0.0", "", "")
control_sustainable_w1 <- rbind(control_sustainable_w1[1:9, ],            
                  new_row,
                  control_sustainable_w1[- (1:9), ])
balance_test_survey1 <- cbind(control_sustainable_w1, control_unsustainable_w1)
balance_test_survey1 <- balance_test_survey1[-c(9:12)]
balance_test_survey1 %>% 
  kbl(caption = "Characteristics of people who dropped out in the treatment vs. the control group in survey 1", booktabs = T, escape = FALSE,linesep = "", format = "latex", row.names = F) %>%
column_spec(3:4, width = "1.5cm") %>%
  column_spec(5:6, width = "2cm") %>%
    column_spec(7, width = "1.2cm") %>%
      column_spec(8, width = "0.6cm") %>%
  column_spec(9:10, width = "1.5cm") %>% 
    column_spec(11, width = "1.2cm") %>%
      column_spec(12, width = "0.6cm") %>%
            kable_styling(font_size = 10) %>% 
  save_kable("appendix/TableA4_w1.tex")
```

### Wave 2

```{r, include=FALSE}
## clean the data
debt_w2_all<- read.csv("Debt & Preferences - June - Wave 1_August 3, 2022_09.16.csv", colClasses = c("character"), sep = ",")
debt_w2_all <- debt_w2_all[-c(1:2),] # remove unnecessary columns
debt_w2_all <- debt_w2_all[which(debt_w2_all$treat!="9999"),]
#debt <- debt[which(debt_w2_all$Progress=="100"),]

# change the variable names
names(debt_w2_all) <- gsub(x = names(debt_w2_all), pattern = "\\.", replacement = "")  

# creating dummy for speeders
debt_w2_all$duration <- as.numeric(debt_w2_all$Durationinseconds)
debt_w2_all$speeder <- ifelse(debt_w2_all$duration<306 & debt_w2_all$treat==1 |debt_w2_all$duration<364 & debt_w2_all$treat==2 |debt_w2_all$duration<323 & debt_w2_all$treat==3, 1, 0)
table(debt_w2_all$speeder)
# control: 306
# treatmetn 1: 364
# treatment 2: 323

# create a measure for wether respondents passed the sound check and the attention check and did not speed
debt_w2_all$Finished <- as.numeric(debt_w2_all$Finished)
debt_w2_all$soundC <- as.numeric(debt_w2_all$soundC)
debt_w2_all$AC <- as.numeric(debt_w2_all$AC)
debt_w2_all$SC_passed <- ifelse(debt_w2_all$soundC==3, 1, 0)
debt_w2_all$AC_passed <- ifelse(debt_w2_all$AC==8, 1, 0)
debt_w2_all$check <- ifelse(debt_w2_all$speeder==0 & debt_w2_all$soundC==3 & debt_w2_all$AC==8, 1, 0)
unique(debt_w2_all$check)
table(debt_w2_all$treat, debt_w2_all$check)

debt_w2_all$status <- ifelse(debt_w2_all$check==1, "Complete", NA)
debt_w2_all$status <- ifelse(debt_w2_all$AC_passed==0, "Attention check failed", debt_w2_all$status)
debt_w2_all$status <- ifelse(debt_w2_all$SC_passed==0, "Sound check failed", debt_w2_all$status)
debt_w2_all$status <- ifelse(debt_w2_all$speeder==1, "Speeder", debt_w2_all$status)
debt_w2_all$status <- ifelse(debt_w2_all$agreed==0, "No consent", debt_w2_all$status)
debt_w2_all$status <- ifelse(debt_w2_all$followup==2, "No consent to follow up", debt_w2_all$status)
debt_w2_all$status <- ifelse(debt_w2_all$Finished==0, "Not finished", debt_w2_all$status)
debt_w2_all$status <- ifelse(debt_w2_all$yrbrn!="" & debt_w2_all$MC_debt_V1_1=="" & debt_w2_all$MC_debt_V1_2=="" & debt_w2_all$MC_debt_V2_3=="" & debt_w2_all$MC_debt_V2_4=="", "Quota full", debt_w2_all$status)

debt_w2_all$status <- ifelse(is.na(debt_w2_all$status), "Not finished", debt_w2_all$status)
```

```{r, include=FALSE}
## recode control variables
debt_w2_all$age <-2021-as.numeric(debt_w2_all$yrbrn)
debt_w2_all$age_qua <- debt_w2_all$age^2
debt_w2_all$age_rec <- ifelse(debt_w2_all$age<35, "Up to 35", ifelse(debt_w2_all$age>=35 & debt_w2_all$age<51, "35-50", ifelse(debt_w2_all$age>=51 & debt_w2_all$age<65, "51-65", ifelse(debt_w2_all$age>=65, "65+", NA))))

# gender
debt_w2_all$gender_rec <- ifelse(debt_w2_all$gender==1, 1, ifelse(debt_w2_all$gender==2 |debt_w2_all$gender==3, 0, NA))
debt_w2_all$gender_rec2 <- ifelse(debt_w2_all$gender==1, "Female", ifelse(debt_w2_all$gender==2 |debt_w2_all$gender==3, "Male", NA))

#education
debt_w2_all$educ <- as.numeric(debt_w2_all$educ)
debt_w2_all$edu_rec <- ifelse(debt_w2_all$educ==1 | debt_w2_all$educ==2 | debt_w2_all$educ ==3, 1, # Below A-Levels
                              ifelse(debt_w2_all$educ==4, 2, # A-Levels
                                     ifelse(debt_w2_all$educ==5 | debt_w2_all$educ==6, 3, # Foundation Degree, etc
                                            ifelse(debt_w2_all$educ==7, 4, # BA
                                                   ifelse(debt_w2_all$educ==8 |debt_w2_all$educ==9, 5, NA))))) #MA plus
table(debt_w2_all$edu_rec)
debt_w2_all$edu_rec2 <- ifelse(debt_w2_all$edu_rec>=3, "High",  
                        ifelse(debt_w2_all$edu_rec==2, "Middle",
                               ifelse(debt_w2_all$edu_rec==1, "Low", debt_w2_all$edu_rec)))

#employment (this needs to be edited)
debt_w2_all$emp <- as.numeric(debt_w2_all$emp)
debt_w2_all$emp_rec <- ifelse(debt_w2_all$emp==10 | debt_w2_all$emp==11 | debt_w2_all$emp==16, "Employed or student",
                       ifelse(debt_w2_all$emp==12 | debt_w2_all$emp==13, "Unemployed", 
                              ifelse(debt_w2_all$emp==15, "Retired", 
                                     ifelse(debt_w2_all$emp==14 | debt_w2_all$emp ==17 | debt_w2_all$emp == 18, "Out of work force", NA))))

#income
debt_w2_all$income <- debt_w2_all$hhinc_w
debt_w2_all$income <- ifelse(debt_w2_all$income=="", debt_w2_all$hhinc_m, debt_w2_all$income)
debt_w2_all$income <- ifelse(debt_w2_all$income=="", debt_w2_all$hhinc_y, debt_w2_all$income)
debt_w2_all$income <- ifelse(debt_w2_all$income=="" | debt_w2_all$income=="99" | debt_w2_all$income=="88", NA, debt_w2_all$income)
debt_w2_all$income <- as.numeric(debt_w2_all$income)
debt_w2_all$income_cat <- ifelse(debt_w2_all$income<=3, "Low",
                          ifelse(debt_w2_all$income==4 |debt_w2_all$income==5 |debt_w2_all$income==6 |debt_w2_all$income==7, "Middle",
                                 ifelse(debt_w2_all$income>=8, "High", NA)))

# political variables / mediators vote
debt_w2_all$vote_part1 <- as.numeric(debt_w2_all$vote_part1)
debt_w2_all$vote_part2 <- as.numeric(debt_w2_all$vote_part2)

debt_w2_all$party_1 <- ifelse(debt_w2_all$vote_part1 == 1 | debt_w2_all$vote_part1 == 7 | debt_w2_all$vote_part1 == 8, "Right-wing",
                       ifelse(debt_w2_all$vote_part1 == 2 | debt_w2_all$vote_part1 == 4 | debt_w2_all$vote_part1 == 5 | debt_w2_all$vote_part1 == 6, "Left-wing",
                              ifelse(debt_w2_all$vote_par1t1 == 3, "Lib Dems",
                                     ifelse(debt_w2_all$vote_part1 == 9 | debt_w2_all$vote_part1 == 88, "Other", NA))))

debt_w2_all$party_2 <- ifelse(debt_w2_all$vote_part2 == 1 | debt_w2_all$vote_part2 == 5 | debt_w2_all$vote_part2 == 7 | debt_w2_all$vote_part2 == 8, "Right-wing",
                       ifelse(debt_w2_all$vote_part2 == 2 | debt_w2_all$vote_part2 == 4 | debt_w2_all$vote_part2 == 6, "Left-wing",
                              ifelse(debt_w2_all$vote_part2 == 3, "Lib Dems",
                                     ifelse(debt_w2_all$vote_part2 == 9 | debt_w2_all$vote_part2 == 88, "Other", NA))))
debt_w2_all$party <- debt_w2_all$party_1
debt_w2_all$party <- ifelse(debt_w2_all$party=="" | is.na(debt_w2_all$party), debt_w2_all$party_2, debt_w2_all$party)


# certainty on debt
debt_w2_all$cert_debt <- debt_w2_all$cert_debt_V1_1 
debt_w2_all$cert_debt <- ifelse(debt_w2_all$cert_debt =="", debt_w2_all$cert_debt_V1_2, debt_w2_all$cert_debt)
debt_w2_all$cert_debt <- ifelse(debt_w2_all$cert_debt =="", debt_w2_all$cert_debt_V2_3, debt_w2_all$cert_debt)
debt_w2_all$cert_debt <- ifelse(debt_w2_all$cert_debt =="", debt_w2_all$cert_debt_V2_4, debt_w2_all$cert_debt)
debt_w2_all$cert_debt <- as.numeric(debt_w2_all$cert_debt)
table(debt_w2_all$cert_debt)
debt_w2_all$cert_debt_rec <- ifelse(debt_w2_all$cert_debt==3, "Serious problem",
                             ifelse(debt_w2_all$cert_debt==2, "Uncertain",
                                    ifelse(debt_w2_all$cert_debt==1, "Not a serious problem", NA)))
debt_w2_all$cert_debt_rec <- as.factor(debt_w2_all$cert_debt_rec)


# having thought about debt
debt_w2_all$think_debt <- debt_w2_all$think_debt_V1_1 
debt_w2_all$think_debt <- ifelse(debt_w2_all$think_debt =="", debt_w2_all$think_debt_V2_2, debt_w2_all$think_debt)
debt_w2_all$think_debt <- ifelse(debt_w2_all$think_debt =="", debt_w2_all$think_debt_V1_3, debt_w2_all$think_debt)
debt_w2_all$think_debt <- ifelse(debt_w2_all$think_debt =="", debt_w2_all$think_debt_V2_4, debt_w2_all$think_debt)
debt_w2_all$think_debt <- as.numeric(debt_w2_all$think_debt)
table(debt_w2_all$think_debt)
debt_w2_all$think_debt_rec <- ifelse(debt_w2_all$think_debt==4, "A great deal",
                          ifelse(debt_w2_all$think_debt==3, "Moderate amount",
                             ifelse(debt_w2_all$think_debt==2, "A little",
                                    ifelse(debt_w2_all$think_debt==1, "Never", NA))))
debt_w2_all$think_debt_rec <- as.factor(debt_w2_all$think_debt_rec)

# concern over debt
debt_w2_all$debt_pre <- debt_w2_all$MC_debt_V1_1 
debt_w2_all$debt_pre <- ifelse(debt_w2_all$debt_pre =="", debt_w2_all$MC_debt_V1_2, debt_w2_all$debt_pre)
debt_w2_all$debt_pre <- ifelse(debt_w2_all$debt_pre =="", debt_w2_all$MC_debt_V2_3, debt_w2_all$debt_pre)
debt_w2_all$debt_pre <- ifelse(debt_w2_all$debt_pre =="", debt_w2_all$MC_debt_V2_4, debt_w2_all$debt_pre)
debt_w2_all$debt_pre <- as.numeric(debt_w2_all$debt_pre)
table(debt_w2_all$debt_pre)
```

```{r, results = 'asis', message=F, echo=FALSE}
debt_w2_all <- debt_w2_all[which(duplicated(debt_w2_all$respid)==F),]

lm.1_w2_all <- lm(Finished ~ treat +  as.factor(debt_pre) + as.factor(block), data = debt_w2_all)
lm.2_w2_all <- lm(Finished ~ treat + age + gender_rec2 + edu_rec2 + party + income_cat +cert_debt_rec + think_debt_rec + emp_rec+ as.factor(debt_pre) + as.factor(block), data = debt_w2_all)

#modelsummary(list("M1" = lm.1_w2_all, "M2" = lm.2_w2_all), stars = TRUE, title="Regression table: Determinants of finishing survey 2", coef_rename = c("treat2" = "Sustainable", "treat3" = "Unsustainable", "age" = "Age", "gender_rec2Male"= "Male (ref.: female)", "partyLib Dems" = "Lib Dems (ref.: left-wing)", "partyOther"= "Other parties (ref.: left-wing)", "partyRight-wing"="Right-wing (ref.: left-wing)", "income_catLow"="Low income (ref.: high)", "income_catMiddle"="Middle income (ref.: high)", "cert_debt_recSerious problem"= "Debt serious problem (ref.: not serious)", "cert_debt_recUncertain"= "Debt uncertain (ref.: not serious)", "think_debt_recA little"=" Thought about debt a little (ref.: a great deal)", "think_debt_recModerate amount"="Thought about debt moderate amount (ref.: a great deal)", "think_debt_recNever"="Thought never about debt (ref.: a great deal)", "emp_recOut of work force"="Out of work force (ref.: employed or student)", "emp_recRetired"="Retired (ref.: employed or student)", "emp_recUnemployed"="Unemployed (ref.: employed or student)", "edu_rec2Low"="Low education (ref.: high)", "edu_rec2Middle"="Middle education (ref.: high)"), coef_omit = "as.factor", output = 'tables/dropout_regression_survey2.tex')

df_summary <- debt_w2_all[which(debt_w2_all$Finished!=1),] %>%
mutate(Treatment = ifelse(treat==1, "Control", ifelse(treat==2, "Sustainable", ifelse(treat==3, "Unsustainable", NA))),
         edu_rec2_num = ifelse(edu_rec2=="Low", 0, ifelse(edu_rec2=="Middle", 1,     ifelse(edu_rec2=="High", 2, NA))),
         income_cat_num = ifelse(income_cat=="Low", 0, ifelse(income_cat=="Middle", 1,     ifelse(income_cat=="High", 2, NA))),
         cert_debt_rec_num = ifelse(cert_debt_rec=="Not a serious problem", 0, ifelse(cert_debt_rec=="Uncertain", 1,     ifelse(cert_debt_rec=="Serious problem", 2, NA))),
         think_debt_rec_num = ifelse(think_debt_rec=="Never", 0, ifelse(think_debt_rec=="A little", 1,     ifelse(think_debt_rec=="Moderate amount", 2, ifelse(think_debt_rec=="A great deal", 3,NA))))) %>% 
  dplyr::select(Treatment,
         `Age` = age,
         `Female` = gender_rec2,
         `Education` = edu_rec2_num,
         `Left-right placement` = party,
         `Income` = income_cat_num,
         `Prior concern` = cert_debt_rec_num,
        `Thought about debt` = think_debt_rec_num)

control_sustainable_w2 <- datasummary_balance(~Treatment,
                    data = df_summary[which(df_summary$Treatment!="Sustainable"),], modelsummary_format_numeric_latex = "plain", dinm = T, dinm_statistic="p.value", stars=T, escape = FALSE, output = "data.frame")
control_unsustainable_w2 <- datasummary_balance(~Treatment,
                    data = df_summary[which(df_summary$Treatment!="Unsustainable"),], modelsummary_format_numeric_latex = "plain", dinm = T, dinm_statistic="p.value", stars=T, escape = FALSE, output = "data.frame")
balance_test_survey2 <- cbind(control_sustainable_w2, control_unsustainable_w2)
balance_test_survey2 <- balance_test_survey2[-c(9:12)]
balance_test_survey2 %>% 
  kbl(caption = "Characteristics of people who dropped out in the treatment vs. the control group in survey 2", booktabs = T, escape = FALSE,linesep = "", format = "latex") %>%
column_spec(3:4, width = "1.5cm") %>%
  column_spec(5:6, width = "2cm") %>%
    column_spec(7, width = "1.2cm") %>%
      column_spec(8, width = "0.6cm") %>%
  column_spec(9:10, width = "1.5cm") %>% 
    column_spec(11, width = "1.2cm") %>%
      column_spec(12, width = "0.6cm") %>%
            kable_styling(font_size = 10) %>% 
  save_kable("appendix/TableA4_w2.tex")
```

## Table A.5: Determinants of participating in the follow-up wave (Survey 2) 

```{r, results = 'asis', message=F, echo=FALSE}
debt_w3 <- read.csv("Debt & Preferences - June - Wave 2_September 12, 2022_04.50.csv", colClasses = c("character"), sep = ",")
debt_w3 <- debt_w3[-c(1:2),] # remove unnecessary columns

respid_w3 <- debt_w3$respid
debt_w2$followup_participation <- ifelse(debt_w2$respid_w2 %in% respid_w3, 1, 0)
debt_w2_w3$followup_participation <- ifelse(debt_w2_w3$respid_w2  %in% respid_w3, 1, 0)

df_w2_followup_summary <- debt_w2 %>%
  mutate(followup_rec = ifelse(followup_participation==0, "No follow up", ifelse(followup_participation==1, "Follow up", NA)),
         edu_rec_w2_num = ifelse(edu_rec_w2=="Low", 0, ifelse(edu_rec_w2=="Middle", 1,     ifelse(edu_rec_w2=="High", 2, NA))),
         income_cat_w2_num = ifelse(income_cat_w2=="Low", 0, ifelse(income_cat_w2=="Middle", 1,     ifelse(income_cat_w2=="High", 2, NA))),
         cert_debt_rec_w2_num = ifelse(cert_debt_rec_w2=="Not a serious problem", 0, ifelse(cert_debt_rec_w2=="Uncertain", 1,     ifelse(cert_debt_rec_w2=="Serious problem", 2, NA))),
         think_debt_rec_w2_num = ifelse(think_debt_rec_w2=="Never", 0, ifelse(think_debt_rec_w2=="A little", 1,     ifelse(think_debt_rec_w2=="Moderate amount", 2, ifelse(think_debt_rec_w2=="A great deal", 3,NA))))) %>% 
  dplyr::select(Followup = followup_rec,
         `Age` = age_w2,
         `Female` = gender_rec_w2,
         `Education` = edu_rec_w2_num,
         `Left-right placement` = party_w2,
         `Income` = income_cat_w2_num,
         `Prior concern` = cert_debt_rec_w2_num,
        `Thought about debt` = think_debt_rec_w2_num)
datasummary_balance(~Followup,
                    data = df_w2_followup_summary,
                    title = "Balance check between respondents participating in follow-up and not participating", modelsummary_format_numeric_latex = "plain", dinm = T, dinm_statistic = "p.value")
datasummary_balance(~Followup,
                    data = df_w2_followup_summary,
                    title = "Balance check between respondents participating in follow-up and not participating", modelsummary_format_numeric_latex = "plain", dinm = T, dinm_statistic = "p.value")
```

```{r, results = 'asis', message=F, echo=FALSE}
# DV: Participated in the follow up (1 = Yes, 0 = No) 
# IV, Model 1: Treatment group (1, 2 or Control) 
lm.1 <- lm(followup_participation ~ treat_w2, data = debt_w2)

# IV, Model 2: Treatment group (1, 2 or Control ) + socio-demographic characteristics
lm.2 <- lm(followup_participation ~ treat_w2 + age_w2 + gender_rec_w2+ party_w2+ income_cat_w2 + cert_debt_rec_w2 +think_debt_rec_w2 + emp_rec_w2, data = debt_w2)

# IV, Model 3: Treatment group (1, 2 or Control) Treatment group (1, 2, or Control) interacted with a variable that measures the difference between concern about debt before treatment and concern about debt after treatment (debt_post_w2 – debt_pre_w2)
debt_w2$diff_post2_pre2 <- debt_w2$debt_post_w2*5 - debt_w2$debt_pre_w2
lm.3 <- lm(followup_participation ~ treat_w2*diff_post2_pre2, data = debt_w2)

# IV, Model 4: Add socio-demographic characteristics to model 3
lm.4 <- lm(followup_participation ~ treat_w2*diff_post2_pre2 + age_w2 + gender_rec_w2+ party_w2+ income_cat_w2 + cert_debt_rec_w2 +think_debt_rec_w2 + emp_rec_w2, data = debt_w2)

modelsummary(list("M1" = lm.1, "M2" = lm.2, "M3" = lm.3, "M4" = lm.4), stars = TRUE, title="Regression table: Determinants of participating in the follow-up", coef_rename = c("treat_w22" = "Sustainable", "treat_w23" = "Unsustainable", "age_w2" = "Age", "gender_rec_w2Male"= "Male (ref.: female)", "party_w2Lib Dems" = "Lib Dems (ref.: left-wing)", "party_w2Other"= "Other parties (ref.: left-wing)", "party_w2Right-wing"="Right-wing (ref.: left-wing)", "income_cat_w2Low"="Low income (ref.: high)", "income_cat_w2Middle"="Middle income (ref.: high)", "cert_debt_rec_w2Serious problem"= "Debt serious problem (ref.: not serious)", "cert_debt_rec_w2Uncertain"= "Debt uncertain (ref.: not serious)", "think_debt_rec_w2A little"=" Thought about debt a little (ref.: a great deal)", "think_debt_rec_w2Moderate amount"="Thought about debt moderate amount (ref.: a great deal)", "think_debt_rec_w2Never"="Thought never about debt (ref.: a great deal)", "emp_rec_w2Out of work force"="Out of work force (ref.: employed or student)", "emp_rec_w2Retired"="Retired (ref.: employed or student)", "emp_rec_w2Unemployed"="Unemployed (ref.: employed or student)", "diff_post2_pre2"="Difference in pre and post concern ", "treat_w22:diff_post2_pre2"="Sustainable x Difference in concern", "treat_w23:diff_post2_pre2"="Unsustainable x Difference in concern"))

modelsummary(list("M1" = lm.1, "M2" = lm.2, "M3" = lm.3, "M4" = lm.4), stars = TRUE, title="Regression table: Determinants of participating in the follow-up", coef_rename = c("treat_w22" = "Sustainable", "treat_w23" = "Unsustainable", "age_w2" = "Age", "gender_rec_w2Male"= "Male (ref.: female)", "party_w2Lib Dems" = "Lib Dems (ref.: left-wing)", "party_w2Other"= "Other parties (ref.: left-wing)", "party_w2Right-wing"="Right-wing (ref.: left-wing)", "income_cat_w2Low"="Low income (ref.: high)", "income_cat_w2Middle"="Middle income (ref.: high)", "cert_debt_rec_w2Serious problem"= "Debt serious problem (ref.: not serious)", "cert_debt_rec_w2Uncertain"= "Debt uncertain (ref.: not serious)", "think_debt_rec_w2A little"=" Thought about debt a little (ref.: a great deal)", "think_debt_rec_w2Moderate amount"="Thought about debt moderate amount (ref.: a great deal)", "think_debt_rec_w2Never"="Thought never about debt (ref.: a great deal)", "emp_rec_w2Out of work force"="Out of work force (ref.: employed or student)", "emp_rec_w2Retired"="Retired (ref.: employed or student)", "emp_rec_w2Unemployed"="Unemployed (ref.: employed or student)", "diff_post2_pre2"="Difference in pre and post concern ", "treat_w22:diff_post2_pre2"="Sustainable x Difference in concern", "treat_w23:diff_post2_pre2"="Unsustainable x Difference in concern"), output = "appendix/TableA5.tex")
```

# Appendix C: Test 1

## Figure C.1: Distribution of repsonses to the debt aversion items in Surveys 1 and 2

```{r, results = 'asis', message=F, echo=FALSE}
# wave 1: calculate distribution of responses of items for the debt aversion index

# subset only to control group
debt_w1_rec <- debt_w1[which(debt_w1$treat_w1==1),]

# all respondents in control
aversion_w1_all <- datasummary(as.factor(pol1_rec_w1) + as.factor(pol2_rec_w1) + as.factor(pol3_rec_w1) ~ Percent("col"), data = debt_w1_rec, output = 'data.frame')

values <- c(rep("deficit", 4), rep("debt", 4), rep("importance", 4))
aversion_w1_all$item <- values
aversion_w1_all$sample <- "Full"

# only labour
aversion_w1_L <- datasummary(as.factor(pol1_rec_w1) + as.factor(pol2_rec_w1) + as.factor(pol3_rec_w1) ~ Percent("col"), data = debt_w1_rec[which(debt_w1_rec$party_rec_w1 == "Labour"),], output = 'data.frame')

values <- c(rep("deficit", 4), rep("debt", 4), rep("importance", 4))
aversion_w1_L$item <- values
aversion_w1_L$sample <- "Labour"

# only conservatives
aversion_w1_C <- datasummary(as.factor(pol1_rec_w1) + as.factor(pol2_rec_w1) + as.factor(pol3_rec_w1) ~ Percent("col"), data = debt_w1_rec[which(debt_w1_rec$party_rec_w1 == "Conservatives"),], output = 'data.frame')

values <- c(rep("deficit", 4), rep("debt", 4), rep("importance", 4))
aversion_w1_C$item <- values
aversion_w1_C$sample <- "Conservatives"

# combine the results
aversion_w1 <- rbind(aversion_w1_all, aversion_w1_L)
aversion_w1 <- rbind(aversion_w1, aversion_w1_C)
aversion_w1$share <- as.numeric(aversion_w1$Percent)/100
aversion_w1$response <- aversion_w1[,2]
aversion_w1$sample <- factor(aversion_w1$sample , levels = c("Full", "Labour", "Conservatives"))

# plot a graph for the deficit
aversion_deficit_w1 <- ggplot(aversion_w1[which(aversion_w1$item=="deficit"),], aes(x = response, y = share, fill = sample)) +
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey40", "grey60", "grey80")) +
      theme_minimal() +
      labs(y = "Share", x = "", fill = NULL) +
      ggtitle("Survey 1, Deficit") +
      theme(plot.title = element_text(face = "bold"))
aversion_deficit_w1

aversion_debt_w1 <- ggplot(aversion_w1[which(aversion_w1$item=="debt"),], aes(x = response, y = share, fill = sample)) +
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey40", "grey60", "grey80")) +
      theme_minimal() +
      labs(y = "Share", x = "", fill = NULL) +
      ggtitle("Survey 1, Debt") +
      theme(plot.title = element_text(face = "bold"))
aversion_debt_w1

aversion_import_w1 <- ggplot(aversion_w1[which(aversion_w1$item=="importance"),], aes(x = response, y = share, fill = sample)) +
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey40", "grey60", "grey80")) +
      theme_minimal() +
      labs(y = "Share", x = "", fill = NULL) +
      ggtitle("Survey 1, Importance") +
      theme(plot.title = element_text(face = "bold"))
aversion_import_w1

# wave 2: calculate distribution of responses of items for the debt aversion index

# subset only to control
debt_w2_w3_rec <- debt_w2_w3[which(debt_w2_w3$treat_w2!=2 & debt_w2_w3$treat_w2!=3),]

# all respondents in control
aversion_w2_all <- datasummary(as.factor(pol1_rec_w2) + as.factor(pol2_rec_w2) + as.factor(pol3_rec_w2) ~ Percent("col"), data = debt_w2_w3_rec, output = 'data.frame')

values <- c(rep("deficit", 4), rep("debt", 4), rep("importance", 4))
aversion_w2_all$item <- values
aversion_w2_all$sample <- "Full"

# only labour
aversion_w2_L <- datasummary(as.factor(pol1_rec_w2) + as.factor(pol2_rec_w2) + as.factor(pol3_rec_w2) ~ Percent("col"), data = debt_w2_w3_rec[which(debt_w2_w3_rec$party_rec_w2 == "Labour"),], output = 'data.frame')

values <- c(rep("deficit", 4), rep("debt", 4), rep("importance", 4))
aversion_w2_L$item <- values
aversion_w2_L$sample <- "Labour"

# only conservatives
aversion_w2_C <- datasummary(as.factor(pol1_rec_w2) + as.factor(pol2_rec_w2) + as.factor(pol3_rec_w2) ~ Percent("col"), data = debt_w2_w3_rec[which(debt_w2_w3_rec$party_rec_w2 == "Conservatives"),], output = 'data.frame')

values <- c(rep("deficit", 4), rep("debt", 4), rep("importance", 4))
aversion_w2_C$item <- values
aversion_w2_C$sample <- "Conservatives"

# combine the results
aversion_w2 <- rbind(aversion_w2_all, aversion_w2_L)
aversion_w2 <- rbind(aversion_w2, aversion_w2_C)
aversion_w2$share <- as.numeric(aversion_w2$Percent)/100
aversion_w2$response <- aversion_w2[,2]
aversion_w2$sample <- factor(aversion_w2$sample , levels = c("Full", "Labour", "Conservatives"))

# plot a graph for the deficit question
aversion_deficit_w2 <- ggplot(aversion_w2[which(aversion_w2$item=="deficit"),], aes(x = response, y = share, fill = sample)) +
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey40", "grey60", "grey80")) +
      theme_minimal() +
      labs(y = "Share", x = "", fill = NULL) +
      ggtitle("Survey 2, Deficit") +
      theme(plot.title = element_text(face = "bold"))
aversion_deficit_w2

# plot a graph for the debt question
aversion_debt_w2 <- ggplot(aversion_w2[which(aversion_w2$item=="debt"),], aes(x = response, y = share, fill = sample)) +
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey40", "grey60", "grey80")) +
      theme_minimal() +
      labs(y = "Share", x = "", fill = NULL) +
      ggtitle("Survey 2, Debt") +
      theme(plot.title = element_text(face = "bold"))
aversion_debt_w2

# plot a graph for the importance question
aversion_import_w2 <- ggplot(aversion_w2[which(aversion_w2$item=="importance"),], aes(x = response, y = share, fill = sample)) +
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey40", "grey60", "grey80")) +
      theme_minimal() +
      labs(y = "Share", x = "", fill = NULL) +
      ggtitle("Survey 2, Importance") +
      theme(plot.title = element_text(face = "bold"))
aversion_import_w2

# combine the graphs and save it
aversion_items <- ggarrange(aversion_deficit_w1, aversion_deficit_w2,
                            aversion_debt_w1, aversion_debt_w2,
                            aversion_import_w1, aversion_import_w2,
                            nrow=3, ncol=2, common.legend = T, legend="bottom")
ggsave(width = 18, height = 18, units = c("cm"), file ="appendix/FigureC1.pdf")
```

## Table C.1: How Serious?

```{r, results = 'asis', message=F, echo=FALSE}
# table: serious problem?
avg_concern_w1 <- datasummary(debt_pre_w1 + climate_pre_w1 + immi_pre_w1 + china_pre_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1)
avg_concern_w1_L <- datasummary(debt_pre_w1 + climate_pre_w1 + immi_pre_w1 + china_pre_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1[which(debt_w1$party_rec_w1 == "Labour"),])
avg_concern_w1_C <- datasummary(debt_pre_w1 + climate_pre_w1 + immi_pre_w1 + china_pre_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1[which(debt_w1$party_rec_w1 == "Conservatives"),])

avg_concern_w2 <- datasummary(debt_pre_w2 + climate_pre_w2 + immi_pre_w2 + china_pre_w2 ~ mean*Arguments(na.rm=TRUE), data = debt_w2)
avg_concern_w2_L <- datasummary(debt_pre_w2 + climate_pre_w2 + immi_pre_w2 + china_pre_w2 ~ mean*Arguments(na.rm=TRUE), data = debt_w2[which(debt_w2$party_rec_w2 == "Labour"),])
avg_concern_w2_C <- datasummary(debt_pre_w2 + climate_pre_w2 + immi_pre_w2 + china_pre_w2 ~ mean*Arguments(na.rm=TRUE), data = debt_w2[which(debt_w2$party_rec_w2 == "Conservatives"),])

debt_w1$pd_pre_more <- ifelse(debt_w1$debt_pre_w1 > debt_w1$climate_pre_w1 &
                              debt_w1$debt_pre_w1 > debt_w1$immi_pre_w1 &
                              debt_w1$debt_pre_w1 > debt_w1$china_pre_w1, 1, 0)
debt_w1$pd_pre_less <- ifelse(debt_w1$debt_pre_w1 < debt_w1$climate_pre_w1 &
                              debt_w1$debt_pre_w1 < debt_w1$immi_pre_w1 &
                              debt_w1$debt_pre_w1 < debt_w1$china_pre_w1, 1, 0)

debt_more_less_w1 <- datasummary(as.factor(pd_pre_more) + as.factor(pd_pre_less) ~ Percent("col"), data = debt_w1)
debt_more_less_w1_L <- datasummary(as.factor(pd_pre_more) + as.factor(pd_pre_less) ~ Percent("col"), data = debt_w1[which(debt_w1$party_rec_w1 == "Labour"),])
debt_more_less_w1_C <- datasummary(as.factor(pd_pre_more) + as.factor(pd_pre_less) ~ Percent("col"), data = debt_w1[which(debt_w1$party_rec_w1 == "Conservatives"),])

debt_w2$pd_pre_more <- ifelse(debt_w2$debt_pre_w2 > debt_w2$climate_pre_w2 &
                              debt_w2$debt_pre_w2 > debt_w2$immi_pre_w2 &
                              debt_w2$debt_pre_w2 > debt_w2$china_pre_w2, 1, 0)
debt_w2$pd_pre_less <- ifelse(debt_w2$debt_pre_w2 < debt_w2$climate_pre_w2 &
                              debt_w2$debt_pre_w2 < debt_w2$immi_pre_w2 &
                              debt_w2$debt_pre_w2 < debt_w2$china_pre_w2, 1, 0)

debt_more_less_w2 <- datasummary(as.factor(pd_pre_more) + as.factor(pd_pre_less) ~ Percent("col"), data = debt_w2)
debt_more_less_w2_L <- datasummary(as.factor(pd_pre_more) + as.factor(pd_pre_less) ~ Percent("col"), data = debt_w2[which(debt_w2$party_rec_w2 == "Labour"),])
debt_more_less_w2_C <- datasummary(as.factor(pd_pre_more) + as.factor(pd_pre_less) ~ Percent("col"), data = debt_w2[which(debt_w2$party_rec_w2 == "Conservatives"),])

# table: certainty about problem
cert_debt_w1 <- datasummary(cert_debt_rec_w1 + cert_climate_rec_w1 + cert_immi_rec_w1 + cert_china_rec_w1 ~ Percent("col"), data = debt_w1)
cert_debt_w1_L <- datasummary(cert_debt_rec_w1 + cert_climate_rec_w1 + cert_immi_rec_w1 + cert_china_rec_w1 ~ Percent("col"), data = debt_w1[which(debt_w1$party_rec_w1 == "Labour"),])
cert_debt_w1_C <- datasummary(cert_debt_rec_w1 + cert_climate_rec_w1 + cert_immi_rec_w1 + cert_china_rec_w1 ~ Percent("col"), data = debt_w1[which(debt_w1$party_rec_w1 == "Conservatives"),])
```

## Figure C.2: Distribution of response to the pre-treatment "how serious" items 

```{r, results = 'asis', message=F, echo=FALSE}
# figure: how serious?

# wave 1, all
debt_serious_histo_w1 <- ggplot(debt_w1, aes(debt_pre_w1)) +
      scale_x_continuous("",breaks=c(1,2,3,4,5)) +
      geom_bar(aes(y = (..count..)/sum(..count..))) +
      ylab("Share") +
      theme_minimal() +
      ggtitle("Survey 1, Full Sample") +
      theme(plot.title = element_text(face = "bold"))
debt_serious_histo_w1

# wave 2, all
debt_serious_histo_w2 <- ggplot(debt_w2, aes(debt_pre_w2)) +
      scale_x_continuous("",breaks=c(1,2,3,4,5)) +
      geom_bar(aes(y = (..count..)/sum(..count..))) +
      ylab("Share") +
     theme_minimal() +
      ggtitle("Survey 2, Full Sample") +
      theme(plot.title = element_text(face = "bold"))
debt_serious_histo_w2

# wave 1, by partisanship
serious_party_w1 <- datasummary_crosstab(debt_pre_w1 ~ party_rec_w1, statistic = 1 ~ Percent("col") , data = debt_w1, output = 'data.frame')
serious_party_w1 <- serious_party_w1 %>%
  pivot_longer(
    cols = `Labour`:`Conservatives`,
    names_to = "party",
    values_to = "value"
)

serious_party_w1 <- serious_party_w1 %>% subset(debt_pre_w1!="All") %>% mutate_at(4, as.numeric)
serious_party_w1$value <- serious_party_w1$value/100

debt_serious_histo_w1_party <- ggplot(serious_party_w1, aes(x = debt_pre_w1, y = value, fill = party)) +
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey40", "grey80")) +
      theme_minimal() +
      labs(y = "Share", x = "", fill = NULL) +
      ggtitle("Survey 1, By Partisanship") +
      theme(plot.title = element_text(face = "bold"))
debt_serious_histo_w1_party

# wave 2, by partisanship
serious_party_w2 <- datasummary_crosstab(debt_pre_w2 ~ party_rec_w2, statistic = 1 ~ Percent("col") , data = debt_w2, output = 'data.frame')
serious_party_w2 <- serious_party_w2 %>%
  pivot_longer(
    cols = `Labour`:`Conservatives`,
    names_to = "party",
    values_to = "value"
)

serious_party_w2 <- serious_party_w2 %>% subset(debt_pre_w2!="All") %>% mutate_at(4, as.numeric)
serious_party_w2$value <- serious_party_w2$value/100

debt_serious_histo_w2_party <- ggplot(serious_party_w2, aes(x = debt_pre_w2, y = value, fill = party)) +
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey40", "grey80")) +
      theme_minimal() +
      labs(y = "Share", x = "", fill = NULL) +
      ggtitle("Survey 2, By Partisanship") +
      theme(plot.title = element_text(face = "bold"))
debt_serious_histo_w2_party

ggarrange(debt_serious_histo_w1, debt_serious_histo_w2, debt_serious_histo_w1_party, debt_serious_histo_w2_party,
          nrow=2, ncol=2, common.legend = T, legend="bottom")
ggsave(width = 18, height = 15, units = c("cm"), file ="appendix/FigureC2.pdf")
```

## Figure C.3: Replicating Figure 2 for Survey 2: Share of respondents who prioritize debt over competing issues including inflation support

```{r, results = 'asis', message=F, echo=FALSE}
# subset to only two parties
debt_w2_rec <- debt_w2[which(debt_w2$party_rec_w2=="Labour" | debt_w2$party_rec_w2=="Conservatives"),]

# subset only to control group
debt_w2_rec <- debt_w2_rec[which(debt_w2_rec$treat_w2!=2 & debt_w2_rec$treat_w2!=3),]

# priority given to debt...
debt_CC_rec_w2_df <- datasummary_crosstab(debt_CC_rec_w2 ~ party_rec_w2, statistic = 1 ~ Percent("col") , data = debt_w2_rec, output = 'data.frame')
debt_immi_rec_w2_df <- datasummary_crosstab(debt_immi_rec_w2 ~ party_rec_w2, statistic = 1 ~ Percent("col") , data = debt_w2_rec, output = 'data.frame')
debt_nhs_rec_w2_df <- datasummary_crosstab(debt_nhs_rec_w2 ~ party_rec_w2, statistic = 1 ~ Percent("col") , data = debt_w2_rec, output = 'data.frame')
debt_infl_rec_w2_df <- datasummary_crosstab(debt_infl_rec_w2 ~ party_rec_w2, statistic = 1 ~ Percent("col") , data = debt_w2_rec, output = 'data.frame')

debt_CC_rec_w2_df <- debt_CC_rec_w2_df %>% rename(priority=debt_CC_rec_w2)
debt_CC_rec_w2_df$Topic <- "Climate change"
debt_immi_rec_w2_df <- debt_immi_rec_w2_df %>% rename(priority=debt_immi_rec_w2)
debt_immi_rec_w2_df$Topic <- "Immigration"
debt_nhs_rec_w2_df <- debt_nhs_rec_w2_df %>% rename(priority=debt_nhs_rec_w2)
debt_nhs_rec_w2_df$Topic <- "NHS"
debt_infl_rec_w2_df <- debt_infl_rec_w2_df %>% rename(priority=debt_infl_rec_w2)
debt_infl_rec_w2_df$Topic <- "Inflation support"

df_priority <- rbind(debt_CC_rec_w2_df[,-2], debt_immi_rec_w2_df[,-2], debt_nhs_rec_w2_df[,-2], debt_infl_rec_w2_df[,-2])
df_priority <- df_priority %>% 
  pivot_longer(
    cols = `Labour`:`Conservatives`, 
    names_to = "party",
    values_to = "value")
df_priority <- df_priority %>% subset(priority!="All") %>% mutate_at(4, as.numeric)
df_priority$value <- df_priority$value/100
df_priority$priority <- ifelse(df_priority$priority==0, "Debt is not priority", ifelse(df_priority$priority==1, "Debt is priority", NA))

# Set the factor levels before plotting
df_priority$Topic <- factor(df_priority$Topic, 
                           levels = c("Climate change", "Immigration", "NHS", "Inflation support"))

gg_prio_simple_w2 <- ggplot(df_priority[which(df_priority$priority == "Debt is priority"),], aes(x = party, y = value, fill = party)) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = c("grey40", "grey80")) +
  facet_grid(~ Topic, scales = "free") +
  labs(y = "Share", x = "Partisanship") +
  theme_minimal() +
  theme(legend.position = "none") +
  geom_text(aes(label = value), size = 2.5, color = "black", position = position_stack(vjust = 0.5)) +
  ylim(0, 0.62)
#gg_prio_simple_w2

# how often given prio? 
debt_w2_rec$sum_debt_prio <- debt_w2_rec$debt_CC_rec_w2+ debt_w2_rec$debt_immi_rec_w2 + debt_w2_rec$debt_nhs_rec_w2 + debt_w2_rec$debt_infl_rec_w2
debt_w2_rec$sum_debt_prio_rec <- ifelse(debt_w2_rec$sum_debt_prio==4, "Debt over all 4", ifelse(debt_w2_rec$sum_debt_prio==3, "Debt over at least 3", ifelse(debt_w2_rec$sum_debt_prio==2, "Debt over at least 2", ifelse(debt_w2_rec$sum_debt_prio==0, "Never prio debt", NA))))
sum_debt_prio_rec_w2_df <- datasummary_crosstab(sum_debt_prio_rec ~ party_rec_w2, statistic = 1 ~ Percent("col") , data = debt_w2_rec, output = 'data.frame')

sum_debt_prio_rec_w2_df <- sum_debt_prio_rec_w2_df %>% 
  pivot_longer(
    cols = `Labour`:`Conservatives`, 
    names_to = "party",
    values_to = "value")
sum_debt_prio_rec_w2_df <- sum_debt_prio_rec_w2_df %>% subset(sum_debt_prio_rec!="All") %>% mutate_at(4, as.numeric)
sum_debt_prio_rec_w2_df$value <- sum_debt_prio_rec_w2_df$value/100
sum_debt_prio_rec_w2_df<- sum_debt_prio_rec_w2_df[,-2]

gg_prio_comp_w2 <- ggplot(sum_debt_prio_rec_w2_df, aes(x = party, y = value, fill = party)) + 
      geom_bar(stat = "identity") +
      scale_fill_manual(values = c("grey40", "grey80")) +
      facet_grid(~ sum_debt_prio_rec, scales = "free") + 
      labs(y = "Share", x = "Partisanship") + 
      theme_minimal() + 
      theme(legend.position = "none") +
      geom_text(aes(label = value),size = 2.5, color="black", position = position_stack(vjust = 0.5)) + ylim(0,0.61)
#gg_prio_comp_w2

prio_graph_w2 <- ggarrange(gg_prio_simple_w2, gg_prio_comp_w2, nrow = 1, ncol=2)
prio_graph_w2

ggsave(prio_graph_w2, width = 30, height = 15, units = c("cm"), file ="appendix/FigureC3.pdf")
```

```{r, results = 'asis', message=F, echo=FALSE}
# calculate who prioritises debt for all respondents
# how often given prio? 
debt_w1_rec$sum_debt_prio <- debt_w1_rec$debt_CC_rec_w1+ debt_w1_rec$debt_immi_rec_w1 + debt_w1_rec$debt_nhs_rec_w1
debt_w1_rec$sum_debt_prio_rec <- ifelse(debt_w1_rec$sum_debt_prio==3, "Debt over all 3", ifelse(debt_w1_rec$sum_debt_prio==2, "Debt over at least 2", ifelse(debt_w1_rec$sum_debt_prio==0, "Never prio debt", NA)))
sum_debt_prio_rec_w1_df <- datasummary_crosstab(sum_debt_prio_rec ~ party_rec_w1,statistic = 1 ~ Percent("col") , data = debt_w1_rec, output = 'data.frame')

datasummary(debt_CC_rec_w2 + debt_immi_rec_w2 + debt_nhs_rec_w2 + debt_infl_rec_w2 ~ mean*Arguments(na.rm=TRUE), data = debt_w2_rec, fmt = 3)
datasummary(debt_CC_rec_w1 + debt_immi_rec_w1 + debt_nhs_rec_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1_rec, fmt = 3)

datasummary(sum_debt_prio_rec ~ Percent("col"), data = debt_w2_rec, fmt = 3)
datasummary(sum_debt_prio_rec ~ Percent("col"), data = debt_w1_rec, fmt = 3)
```

## Figure C.4: NHS Exercise

```{r, results = 'asis', message=F, echo=FALSE}
# survey 1
# full sample
allocation_w1_all <- datasummary(alloc_debt_w1 + alloc_cuts_edu_w1 + alloc_cuts_benefits_w1 + alloc_tax_income_w1 + alloc_tax_vat_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1_rec, output = 'data.frame', fmt = 3)

allocation_w1_all$sample <- "Full"
colnames(allocation_w1_all)[1] <- "Variable"

# only labour
allocation_w1_L <- datasummary(alloc_debt_w1 + alloc_cuts_edu_w1 + alloc_cuts_benefits_w1 + alloc_tax_income_w1 + alloc_tax_vat_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1_rec[which(debt_w1_rec$party_rec_w1 == "Labour"),], output = 'data.frame', fmt = 3)

allocation_w1_L$sample <- "Labour"
colnames(allocation_w1_L)[1] <- "Variable"

# only conservatives
allocation_w1_C <- datasummary(alloc_debt_w1 + alloc_cuts_edu_w1 + alloc_cuts_benefits_w1 + alloc_tax_income_w1 + alloc_tax_vat_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1_rec[which(debt_w1_rec$party_rec_w1 == "Conservatives"),], output = 'data.frame', fmt = 3)

allocation_w1_C$sample <- "Conservatives"
colnames(allocation_w1_C)[1] <- "Variable"

# combine the results
allocation_w1 <- rbind(allocation_w1_all, allocation_w1_L, allocation_w1_C)
allocation_w1$mean <- (as.numeric(allocation_w1$mean))
allocation_w1$sample <- factor(allocation_w1$sample , levels = c("Conservatives", "Labour", "Full"))
allocation_w1$Variable <- factor(allocation_w1$Variable , levels = c("alloc_cuts_edu_w1", "alloc_cuts_benefits_w1","alloc_tax_vat_w1", "alloc_tax_income_w1","alloc_debt_w1"))

# plot a graph allocation exercise
graph_allocation_w1 <- ggplot(allocation_w1, aes(x = mean, y = Variable, fill = sample)) + 
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey40", "grey60", "grey80"), breaks = c("Full", "Labour","Conservatives"), labels = c("Full", "Labour","Conservatives")) + 
  scale_y_discrete(labels = c("Cutting edu spending", "Cutting benefits", "Increasing VAT", "Increasing inc tax\nprogressively", "Increasing debt")) +
      theme_minimal() +
      labs(y = "", x = "Average points", fill = NULL) +
      ggtitle("NHS Funding Exercise") + 
      theme(plot.title = element_text(face = "bold")) +
      xlim(0, 37)

# nhs funding exercise, survey 2 (this needs to be cleaned up/adjusted)
# full sample
allocation_w2_all <- datasummary(alloc_debt_w2 + alloc_cuts_edu_w2 + alloc_cuts_benefits_w2 + alloc_tax_income_w2 + alloc_tax_vat_w2 ~ mean*Arguments(na.rm=TRUE), data = debt_w2_w3_rec, output = 'data.frame', fmt = 3)

allocation_w2_all$sample <- "Full"
colnames(allocation_w2_all)[1] <- "Variable"

# only labour
allocation_w2_L <- datasummary(alloc_debt_w2 + alloc_cuts_edu_w2 + alloc_cuts_benefits_w2 + alloc_tax_income_w2 + alloc_tax_vat_w2 ~ mean*Arguments(na.rm=TRUE), data = debt_w2_w3_rec[which(debt_w2_w3_rec$party_rec_w2 == "Labour"),], output = 'data.frame', fmt = 3)

allocation_w2_L$sample <- "Labour"
colnames(allocation_w2_L)[1] <- "Variable"

# only conservatives
allocation_w2_C <- datasummary(alloc_debt_w2 + alloc_cuts_edu_w2 + alloc_cuts_benefits_w2 + alloc_tax_income_w2 + alloc_tax_vat_w2 ~ mean*Arguments(na.rm=TRUE), data = debt_w2_w3_rec[which(debt_w2_w3_rec$party_rec_w2 == "Conservatives"),], output = 'data.frame', fmt = 3)

allocation_w2_C$sample <- "Conservatives"
colnames(allocation_w2_C)[1] <- "Variable"

# combine the results
allocation_w2 <- rbind(allocation_w2_all, allocation_w2_L, allocation_w2_C)
allocation_w2$mean <- (as.numeric(allocation_w2$mean))
allocation_w2$sample <- factor(allocation_w2$sample , levels = c("Conservatives", "Labour", "Full"))
allocation_w2$Variable <- factor(allocation_w2$Variable , levels = c("alloc_cuts_edu_w2", "alloc_cuts_benefits_w2","alloc_tax_vat_w2", "alloc_tax_income_w2","alloc_debt_w2"))

# plot a graph for the deficit
graph_allocation_w2 <- ggplot(allocation_w2, aes(x = mean, y = Variable, fill = sample)) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_manual(values = c("grey40", "grey60", "grey80"), breaks = c("Full", "Labour","Conservatives"), labels = c("Full", "Labour","Conservatives")) +
  scale_y_discrete(labels = c("Cutting edu spending", "Cutting benefits", "Increasing VAT", "Increasing inc tax\nprogressively", "Increasing debt")) +
  theme_minimal() +
  labs(y = "", x = "Average points", fill = NULL) +
  ggtitle("Survey 2") +
  theme(plot.title = element_text(face = "bold")) +
  xlim(0, 37)
graph_allocation_w2

## change title in graph_allocation_w1
graph_allocation_w1 <- graph_allocation_w1 + ggtitle("Survey 1")

ggarrange(graph_allocation_w1, graph_allocation_w2 +
                 theme(axis.text.y = element_blank(),
                       axis.title.y = element_blank()),
          common.legend = T, legend = "bottom", nrow = 1, ncol=2, widths = c(1, 0.6))
ggsave(width = 18, height = 12, units = c("cm"), file ="appendix/FigureC4.pdf")
```

## Figure C.5:

```{r, results = 'asis', message=F, echo=FALSE}
# plot results from the allocation exercise in a different way: share of people increasing, decreasing
debt_w1_rec$alloc_debt_w1_rec <- debt_w1_rec$alloc_debt_w1
debt_w1_rec$dd_decrease_w1 <- ifelse(debt_w1_rec$alloc_debt_w1_rec>=20, 0, ifelse(debt_w1_rec$alloc_debt_w1_rec<20, 1, NA))
debt_w1_rec$dd_increase_w1 <- ifelse(debt_w1_rec$alloc_debt_w1_rec<=20, 0, ifelse(debt_w1_rec$alloc_debt_w1_rec>20, 1, NA))

debt_w2_w3_rec$alloc_debt_w2_rec <- debt_w2_w3_rec$alloc_debt_w2
debt_w2_w3_rec$dd_decrease_w2 <- ifelse(debt_w2_w3_rec$alloc_debt_w2_rec>=20, 0, ifelse(debt_w2_w3_rec$alloc_debt_w2_rec<20, 1, NA))
debt_w2_w3_rec$dd_increase_w2 <- ifelse(debt_w2_w3_rec$alloc_debt_w2_rec<=20, 0, ifelse(debt_w2_w3_rec$alloc_debt_w2_rec>20, 1, NA))

# survey 1
# full sample
debt_inc_dec_w1_all <- datasummary(dd_decrease_w1 + dd_increase_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1_rec, output = 'data.frame', fmt = 3)

debt_inc_dec_w1_all$sample <- "Full"
colnames(debt_inc_dec_w1_all)[1] <- "Variable"

# only labour
debt_inc_dec_w1_L <- datasummary(dd_decrease_w1 + dd_increase_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1_rec[which(debt_w1_rec$party_rec_w1 == "Labour"),], output = 'data.frame', fmt = 3)

debt_inc_dec_w1_L$sample <- "Labour"
colnames(debt_inc_dec_w1_L)[1] <- "Variable"

# only conservatives
debt_inc_dec_w1_C <- datasummary(dd_decrease_w1 + dd_increase_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1_rec[which(debt_w1_rec$party_rec_w1 == "Conservatives"),], output = 'data.frame', fmt = 3)

debt_inc_dec_w1_C$sample <- "Conservatives"
colnames(debt_inc_dec_w1_C)[1] <- "Variable"

# combine the results
allocation_inc_dec_w1 <- rbind(debt_inc_dec_w1_all, debt_inc_dec_w1_L, debt_inc_dec_w1_C)
allocation_inc_dec_w1$sample <- factor(allocation_inc_dec_w1$sample , levels = c("Full", "Labour", "Conservatives"))

# plot a graph for the deficit
graph_allocation_inc_dec_w1 <- ggplot(allocation_inc_dec_w1, aes(x = Variable, y = as.numeric(mean), fill = sample)) +
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey40", "grey60", "grey80")) +
      theme_minimal() +
      labs(y = "Share", x = "", fill = NULL) +
      ggtitle("Survey 1") +
      scale_x_discrete(labels = c("Decreasing debt", "Increasing debt")) +
      theme(plot.title = element_text(face = "bold")) +
      ylim(0, 0.41)
graph_allocation_inc_dec_w1

# survey 2
# full sample
debt_inc_dec_w2_all <- datasummary(dd_decrease_w2 + dd_increase_w2 ~ mean*Arguments(na.rm=TRUE), data = debt_w2_w3_rec, output = 'data.frame', fmt = 3)

debt_inc_dec_w2_all$sample <- "Full"
colnames(debt_inc_dec_w2_all)[1] <- "Variable"

# only labour
debt_inc_dec_w2_L <- datasummary(dd_decrease_w2 + dd_increase_w2 ~ mean*Arguments(na.rm=TRUE), data = debt_w2_w3_rec[which(debt_w2_w3_rec$party_rec_w2 == "Labour"),], output = 'data.frame', fmt = 3)

debt_inc_dec_w2_L$sample <- "Labour"
colnames(debt_inc_dec_w2_L)[1] <- "Variable"

# only conservatives
debt_inc_dec_w2_C <- datasummary(dd_decrease_w2 + dd_increase_w2 ~ mean*Arguments(na.rm=TRUE), data = debt_w2_w3_rec[which(debt_w2_w3_rec$party_rec_w2 == "Conservatives"),], output = 'data.frame', fmt = 3)

debt_inc_dec_w2_C$sample <- "Conservatives"
colnames(debt_inc_dec_w2_C)[1] <- "Variable"

# combine the results
allocation_inc_dec_w2 <- rbind(debt_inc_dec_w2_all, debt_inc_dec_w2_L, debt_inc_dec_w2_C)
allocation_inc_dec_w2$sample <- factor(allocation_inc_dec_w2$sample , levels = c("Full", "Labour", "Conservatives"))

# plot a graph for the deficit
graph_allocation_inc_dec_w2 <- ggplot(allocation_inc_dec_w2, aes(x = Variable, y = as.numeric(mean), fill = sample)) +
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey40", "grey60", "grey80")) +
      theme_minimal() +
      labs(y = "Share", x = "", fill = NULL) +
      ggtitle("Survey 2") +
      scale_x_discrete(labels = c("Decreasing debt", "Increasing debt")) +
      theme(plot.title = element_text(face = "bold")) +
      ylim(0, 0.41)
graph_allocation_inc_dec_w2

ggarrange(graph_allocation_inc_dec_w1, graph_allocation_inc_dec_w2 +
                 theme(axis.text.y = element_blank(),
                       axis.title.y = element_blank()),
          common.legend = T, legend = "bottom", nrow = 1, ncol=2)
ggsave(width = 18, height = 10, units = c("cm"), file ="appendix/FigureC5.pdf")
```

## Figure C.6: Average of negative and positive votes in QVSR 

```{r, results = 'asis', message=F, echo=FALSE}
# Figure C.5: Analyze negative and positive votes from qvsr separately 
debt_w2_w3_qvsr <- debt_w2_w3_qvsr %>%
  mutate(
    qvsr_cc_neg = ifelse(qvsr_cc < 0, qvsr_cc, NA),
    qvsr_cc_pos = ifelse(qvsr_cc > 0, qvsr_cc, NA),
    qvsr_nhs_neg = ifelse(qvsr_nhs < 0, qvsr_nhs, NA),
    qvsr_nhs_pos = ifelse(qvsr_nhs > 0, qvsr_nhs, NA),
    qvsr_inflation_neg = ifelse(qvsr_inflation < 0, qvsr_inflation, NA),
    qvsr_inflation_pos = ifelse(qvsr_inflation > 0, qvsr_inflation, NA),
    qvsr_immi_neg = ifelse(qvsr_immi < 0, qvsr_immi, NA),
    qvsr_immi_pos = ifelse(qvsr_immi > 0, qvsr_immi, NA),
    qvsr_debt_neg = ifelse(qvsr_debt < 0, qvsr_debt, NA),
    qvsr_debt_pos = ifelse(qvsr_debt > 0, qvsr_debt, NA)
  )

# full sample
qvsr_all_pos_neg <- datasummary(
  qvsr_cc_neg + qvsr_cc_pos + 
    qvsr_nhs_neg + qvsr_nhs_pos + 
    qvsr_inflation_neg + qvsr_inflation_pos + 
    qvsr_immi_neg + qvsr_immi_pos + 
    qvsr_debt_neg + qvsr_debt_pos ~ 
    mean*Arguments(na.rm=TRUE), 
  data = debt_w2_w3_qvsr, 
  output = 'data.frame',
  fmt = 3
)

qvsr_all_pos_neg$sample <- "Full"
colnames(qvsr_all_pos_neg)[1] <- "Variable"

# only labour
qvsr_L_pos_neg <- datasummary(
  qvsr_cc_neg + qvsr_cc_pos + 
    qvsr_nhs_neg + qvsr_nhs_pos + 
    qvsr_inflation_neg + qvsr_inflation_pos + 
    qvsr_immi_neg + qvsr_immi_pos + 
    qvsr_debt_neg + qvsr_debt_pos ~ 
    mean*Arguments(na.rm=TRUE), 
  data = debt_w2_w3_qvsr[which(debt_w2_w3_qvsr$party_rec_w2 == "Labour"),], 
  output = 'data.frame',
  fmt = 3
)

qvsr_L_pos_neg$sample <- "Labour"
colnames(qvsr_L_pos_neg)[1] <- "Variable"

# only conservatives
qvsr_C_pos_neg <- datasummary(
  qvsr_cc_neg + qvsr_cc_pos + 
    qvsr_nhs_neg + qvsr_nhs_pos + 
    qvsr_inflation_neg + qvsr_inflation_pos + 
    qvsr_immi_neg + qvsr_immi_pos + 
    qvsr_debt_neg + qvsr_debt_pos ~ 
    mean*Arguments(na.rm=TRUE), 
  data = debt_w2_w3_qvsr[which(debt_w2_w3_qvsr$party_rec_w2 == "Conservatives"),], 
  output = 'data.frame',
  fmt = 3
)

qvsr_C_pos_neg$sample <- "Conservatives"
colnames(qvsr_C_pos_neg)[1] <- "Variable"

# combine the results
qvsr_dist_pos_neg <- rbind(qvsr_all_pos_neg, qvsr_L_pos_neg, qvsr_C_pos_neg)
qvsr_dist_pos_neg$mean <- (as.numeric(qvsr_dist_pos_neg$mean))
qvsr_dist_pos_neg$sample <- factor(qvsr_dist_pos_neg$sample , levels = c("Conservatives", "Labour", "Full"))

# Convert data from wide to long format
qvsr_dist_pos_neg <- qvsr_dist_pos_neg %>%
  mutate(
    Type = ifelse(grepl("_neg", Variable), "Negative", "Positive"),  # Create Type column
    Category = gsub("_(neg|pos)", "", Variable)  # Extract base variable name
  )

qvsr_dist_pos_neg$Variable <- factor(qvsr_dist_pos_neg$Variable, levels = c("qvsr_inflation_pos","qvsr_inflation_neg", "qvsr_immi_pos","qvsr_immi_neg","qvsr_nhs_pos", "qvsr_nhs_neg", "qvsr_cc_pos","qvsr_cc_neg", "qvsr_debt_pos", "qvsr_debt_neg"))

# plot a graph for qvsr
graph_qvsr_pos_neg <- ggplot(qvsr_dist_pos_neg, aes(x = mean, y = Variable, fill = sample)) + 
  geom_bar(stat = "identity", position = "dodge") +
  scale_fill_manual(values = c("grey40", "grey60", "grey80"), 
                    breaks = c("Full", "Labour", "Conservatives"), 
                    labels = c("Full", "Labour", "Conservatives")) + 
  scale_y_discrete(
    #breaks = c("qvsr_inflation_neg", "qvsr_immi_neg", "qvsr_nhs_neg", "qvsr_cc_neg", "qvsr_debt_neg"),  # Use only negative variables for labels
    labels = c(
      "qvsr_inflation_neg" = "Inflation support",  
      "qvsr_inflation_pos" = "",  
      "qvsr_immi_neg" = "Immigration",  
      "qvsr_immi_pos" = "",  
      "qvsr_nhs_neg" = "NHS",  
      "qvsr_nhs_pos" = "",  
      "qvsr_cc_neg" = "Climate change",  
      "qvsr_cc_pos" = "",  
      "qvsr_debt_neg" = "Debt",
      "qvsr_debt_pos" = ""
    )
  ) +
  theme_minimal() +
  labs(y = "", x = "Average votes", fill = NULL) +
  theme(plot.title = element_text(face = "bold"),
        axis.text.y = element_text(vjust = 2.25)) 

ggsave(graph_qvsr_pos_neg, width = 16, height = 12, units = c("cm"), file ="appendix/FigureC6.pdf")
```

## Figure C.7: Share of respondents selecting different fioscal policiy as their top priority in QVSR

```{r, results = 'asis', message=F, echo=FALSE}
# Create row-wise max and min variables
debt_w2_w3_qvsr_edited <- debt_w2_w3_qvsr %>%
  # Keep only rows where all priority variables are not missing
  filter(
    !is.na(qvsr_cc),
    !is.na(qvsr_nhs),
    !is.na(qvsr_inflation),
    !is.na(qvsr_immi),
    !is.na(qvsr_debt)
  ) %>%
  # Then calculate max and min
  rowwise() %>%
  mutate(
    max_qvsr = max(qvsr_cc, qvsr_nhs, qvsr_inflation, qvsr_immi, qvsr_debt),
    min_qvsr = min(qvsr_cc, qvsr_nhs, qvsr_inflation, qvsr_immi, qvsr_debt)
  ) %>%
  ungroup()

# Create "top priority" indicator variables
debt_w2_w3_qvsr_edited <- debt_w2_w3_qvsr_edited %>%
  mutate(
    debt_top = case_when(
      is.na(qvsr_debt) ~ NA_real_,
      qvsr_debt == max_qvsr & qvsr_debt > 0 ~ 1,
      qvsr_debt < max_qvsr | qvsr_debt == 0 ~ 0
    ),
    
    CC_top = case_when(
      is.na(qvsr_cc) ~ NA_real_,
      qvsr_cc == max_qvsr & qvsr_cc > 0 ~ 1,
      qvsr_cc < max_qvsr | qvsr_cc == 0 ~ 0
    ),
    
    immi_top = case_when(
      is.na(qvsr_immi) ~ NA_real_,
      qvsr_immi == max_qvsr & qvsr_immi > 0 ~ 1,
      qvsr_immi < max_qvsr | qvsr_immi == 0 ~ 0
    ),
    
    nhs_top = case_when(
      is.na(qvsr_nhs) ~ NA_real_,
      qvsr_nhs == max_qvsr & qvsr_nhs > 0 ~ 1,
      qvsr_nhs < max_qvsr | qvsr_nhs == 0 ~ 0
    ),
    
    infl_top = case_when(
      is.na(qvsr_inflation) ~ NA_real_,
      qvsr_inflation == max_qvsr & qvsr_inflation > 0 ~ 1,
      qvsr_inflation < max_qvsr | qvsr_inflation == 0 ~ 0
    )
  )

calculate_priority_shares <- function(data) {
  data %>%
    # Remove rows with NA in max_qvsr
    filter(!is.na(max_qvsr)) %>%
    # Calculate the counts and total in one step
    summarise(
      total_responses = n(),
      debt_count = sum(debt_top == 1, na.rm = TRUE),
      climate_count = sum(CC_top == 1, na.rm = TRUE),
      immigration_count = sum(immi_top == 1, na.rm = TRUE),
      nhs_count = sum(nhs_top == 1, na.rm = TRUE),
      inflation_count = sum(infl_top == 1, na.rm = TRUE)
    ) %>%
    # Calculate percentages
    mutate(
      Debt = debt_count / total_responses * 100,
      Climate = climate_count / total_responses * 100,
      Immigration = immigration_count / total_responses * 100,
      NHS = nhs_count / total_responses * 100,
      Inflation = inflation_count / total_responses * 100
    ) %>%
    # Remove the count columns to keep only the percentages
    dplyr::select(Debt, Climate, Immigration, NHS, Inflation)
}

# Calculate shares for full sample
all_shares <- calculate_priority_shares(debt_w2_w3_qvsr_edited) %>%
  mutate(Group = "Full")

# Calculate shares for Labour supporters
labour_shares <- debt_w2_w3_qvsr_edited %>%
  filter(party_rec_w2 == "Labour") %>%
  calculate_priority_shares() %>%
  mutate(Group = "Labour")

# Calculate shares for Conservative supporters
conservative_shares <- debt_w2_w3_qvsr_edited %>%
  filter(party_rec_w2 == "Conservatives") %>%
  calculate_priority_shares() %>%
  mutate(Group = "Conservatives")

# Combine the results
combined_shares <- bind_rows(all_shares, labour_shares, conservative_shares)

# Convert to long format for plotting
combined_shares_long <- combined_shares %>%
  pivot_longer(
    cols = c(Debt, Climate, Immigration, NHS, Inflation),
    names_to = "Issue",
    values_to = "Percentage"
  )

# Set the ordering of groups and issues for the plot
combined_shares_long$Group <- factor(combined_shares_long$Group, 
                                     levels = c("Conservatives", "Labour", "Full"))

combined_shares_long$Issue <- factor(combined_shares_long$Issue, 
                                     levels = c("Inflation", "Immigration", "NHS", "Climate", "Debt"))

# Create the plot
qvsr_top <- ggplot(combined_shares_long, aes(x = Issue, y = Percentage, fill = Group)) +
  geom_bar(stat = "identity", position = position_dodge(width = 0.8), width = 0.7) +
  theme_minimal() +
  labs(x = "",
       y = "Percentage",
       fill = ""
  ) +
  coord_flip() + # Horizontal bars
  scale_fill_manual(values = c("grey40", "grey60", "grey80"),
                    breaks = c("Full", "Labour", "Conservatives")) +
  # Relabel the x-axis categories
  scale_x_discrete(labels = function(x) {
    ifelse(x == "Climate", "Climate change",
           ifelse(x == "Inflation", "Inflation support", x))
  }) +
  theme(
    legend.position = "bottom",
    panel.grid.major.y = element_blank(),
    axis.text = element_text(size = 11),
    plot.title = element_text(size = 14, face = "bold")
  ) +
  geom_text(
    aes(label = sprintf("%.1f%%", Percentage)),
    position = position_dodge(width = 0.8),
    hjust = -0.2,
    size = 3.5
  ) +
  ylim(0, max(combined_shares_long$Percentage) * 1.2)  # Add space for labels

ggsave(qvsr_top, width = 16, height = 12, units = c("cm"), file ="appendix/FigureC7.pdf") 
```

### Numbers mentioend in Table C.2
```{r, results = 'asis', message=F, echo=FALSE}
table(debt_w2$wrote_S)
table(debt_w2$prioDebt)
table(debt_w2$prioSupp)

debt_w2$wrote_neither <- ifelse(debt_w2$wrote_S == 1 & 
                                 debt_w2$prioDebt == 0 & 
                                 debt_w2$prioSupp == 0, 1, 0)
table(debt_w2$wrote_neither)
```

# TABLE C.3 - MEANS
```{r, results = 'asis', message=F, echo=FALSE}
# Overall mean (full sample)
cat("Overall mean wroteF:\n")
mean(debt_w2$wrote_S, na.rm = TRUE)

# By vote (full sample)
cat("\nBy vote:\n")
debt_w2 %>% filter(party_w2 == "Left-wing") %>% summarise(wrote_S = mean(wroteF, na.rm = TRUE))
debt_w2 %>% filter(party_w2 == "Right-wing") %>% summarise(wrote_S = mean(wroteF, na.rm = TRUE))
debt_w2 %>% filter(party_rec_w2 == "Labour") %>% summarise(wrote_S = mean(wroteF, na.rm = TRUE))
debt_w2 %>% filter(party_rec_w2 == "Conservatives") %>% summarise(wrote_S = mean(wroteF, na.rm = TRUE))
debt_w2 %>% filter(party_w2 == "Lib Dems") %>% summarise(wrote_S = mean(wroteF, na.rm = TRUE))

# By vote (control group) 
cat("\nBy treatment:\n")
debt_w2 %>% filter(treat == 1) %>% summarise(mean_wroteF = mean(wroteF, na.rm = TRUE))
debt_w2 %>% filter(treat == 1 & party_w2 == "Left-wing") %>% summarise(mean_wroteF = mean(wroteF, na.rm = TRUE))
debt_w2 %>% filter(treat == 1 & party_w2 == "Right-wing") %>% summarise(mean_wroteF = mean(wroteF, na.rm = TRUE))
debt_w2 %>% filter(treat == 1 & party_rec_w2 == "Labour") %>% summarise(mean_wroteF = mean(wroteF, na.rm = TRUE))
debt_w2 %>% filter(treat == 1 & party_rec_w2 == "Conservatives") %>% summarise(mean_wroteF = mean(wroteF, na.rm = TRUE))

# Conditional on wroteF == 1: prioDebt
cat("\nConditional on wroteF == 1 - prioDebt:\n")
debt_w2_wrote <- debt_w2 %>% filter(wroteF == 1)

# full sample
mean(debt_w2_wrote$prioDebt, na.rm = TRUE)
debt_w2_wrote %>% filter(party_w2 == "Left-wing") %>% summarise(mean_priod = mean(prioDebt, na.rm = TRUE))
debt_w2_wrote %>% filter(party_w2 == "Right-wing") %>% summarise(mean_priod = mean(prioDebt, na.rm = TRUE))
debt_w2_wrote %>% filter(party_rec_w2 == "Labour") %>% summarise(mean_priod = mean(prioDebt, na.rm = TRUE))
debt_w2_wrote %>% filter(party_rec_w2 == "Conservatives") %>% summarise(mean_priod = mean(prioDebt, na.rm = TRUE))

# control group 
debt_w2_wrote %>% filter(treat == 1) %>% summarise(mean_priod = mean(prioDebt, na.rm = TRUE))
debt_w2_wrote %>% filter(treat == 1 & party_w2 == "Left-wing") %>% summarise(mean_priod = mean(prioDebt, na.rm = TRUE))
debt_w2_wrote %>% filter(treat == 1 & party_w2 == "Right-wing") %>% summarise(mean_priod = mean(prioDebt, na.rm = TRUE))
debt_w2_wrote %>% filter(treat == 1 & party_rec_w2 == "Labour") %>% summarise(mean_priod = mean(prioDebt, na.rm = TRUE))
debt_w2_wrote %>% filter(treat == 1 & party_rec_w2 == "Conservatives") %>% summarise(mean_priod = mean(prioDebt, na.rm = TRUE))

# Conditional on wroteF == 1: prioSupp
cat("\nConditional on wroteF == 1 - prioSupp:\n")

# overall
mean(debt_w2_wrote$prioSupp, na.rm = TRUE)
debt_w2_wrote %>% filter(party_w2 == "Left-wing") %>% summarise(mean_help = mean(prioSupp, na.rm = TRUE))
debt_w2_wrote %>% filter(party_w2 == "Right-wing") %>% summarise(mean_help = mean(prioSupp, na.rm = TRUE))
debt_w2_wrote %>% filter(party_rec_w2 == "Labour") %>% summarise(mean_help = mean(prioSupp, na.rm = TRUE))
debt_w2_wrote %>% filter(party_rec_w2 == "Conservatives") %>% summarise(mean_help = mean(prioSupp, na.rm = TRUE))

# control group 
debt_w2_wrote %>% filter(treat == 1) %>% summarise(mean_help = mean(prioSupp, na.rm = TRUE))
debt_w2_wrote %>% filter(treat == 1 & party_w2 == "Left-wing") %>% summarise(mean_help = mean(prioSupp, na.rm = TRUE))
debt_w2_wrote %>% filter(treat == 1 & party_w2 == "Right-wing") %>% summarise(mean_help = mean(prioSupp, na.rm = TRUE))
debt_w2_wrote %>% filter(treat == 1 & party_rec_w2 == "Labour") %>% summarise(mean_help = mean(prioSupp, na.rm = TRUE))
debt_w2_wrote %>% filter(treat == 1 & party_rec_w2 == "Conservatives") %>% summarise(mean_help = mean(prioSupp, na.rm = TRUE))
```

## Figure C.8: Letter writing binscatter plots with income 

```{r}
# Function to create binscatter-like plot
create_binscatter <- function(df, y_var, y_label, ylim = NULL, ybreaks = NULL) {
  # Filter income
  plot_data <- df %>%
    filter(income_w2 < 88) %>%
    mutate(income_bin = cut(income_w2, breaks = 5, labels = FALSE))
  
  # Calculate bin means
  bin_means <- plot_data %>%
    group_by(income_bin) %>%
    summarise(
      income_mean = mean(income, na.rm = TRUE),
      y_mean = mean(!!sym(y_var), na.rm = TRUE),
      .groups = "drop"
    )
  
  # Create plot
  p <- ggplot(bin_means, aes(x = income_mean, y = y_mean)) +
    geom_point(size = 3) +
    geom_smooth(method = "lm", se = TRUE, color = "blue", linewidth = 0.8) +
    labs(x = "Income", y = y_label) +
    theme_minimal() +
    theme(
      axis.title = element_text(size = 10),
      axis.text = element_text(size = 9)
    )
  
  # Add y-axis limits and breaks if provided
  if (!is.null(ylim) && !is.null(ybreaks)) {
    p <- p + scale_y_continuous(limits = ylim, breaks = ybreaks)
  }
  
  return(p)
}

# Figure C.8a: Percentage who contributed
fig_c8a <- debt_w2 %>%
  filter(income_w2 < 88) %>%
  mutate(income_bin = cut(income_w2, breaks = 5, labels = FALSE)) %>%
  group_by(income_bin) %>%
  summarise(
    income_mean = mean(income_w2, na.rm = TRUE),
    wroteF_mean = mean(wroteF, na.rm = TRUE),
    .groups = "drop"
  ) %>%
  ggplot(aes(x = income_mean, y = wroteF_mean)) +
  geom_point(size = 3) +
  geom_smooth(method = "lm", se = TRUE, color = "blue", linewidth = 0.8) +
  scale_y_continuous(limits = c(0.3, 0.6), breaks = seq(0.3, 0.6, 0.1)) +
  labs(x = "Income", y = "% who contributed") +
  theme_minimal() +
  theme(
    axis.title = element_text(size = 10),
    axis.text = element_text(size = 9)
  )

# Figure C.8b: Percentage who wrote in favor of fiscal consolidation (conditional on writing)
fig_c8b <- debt_w2 %>%
  filter(income_w2 < 88 & wroteF == 1) %>%
  mutate(income_bin = cut(income_w2, breaks = 5, labels = FALSE)) %>%
  group_by(income_bin) %>%
  summarise(
    income_mean = mean(income_w2, na.rm = TRUE),
    priod_mean = mean(prioDebt, na.rm = TRUE),  # Changed from priod_justi
    .groups = "drop"
  ) %>%
  ggplot(aes(x = income_mean, y = priod_mean)) +
  geom_point(size = 3) +
  geom_smooth(method = "lm", se = TRUE, color = "blue", linewidth = 0.8) +
  scale_y_continuous(limits = c(0, 0.3), breaks = seq(0, 0.3, 0.1)) +
  labs(x = "Income", y = "% who wrote in favor of fiscal conso.") +
  theme_minimal() +
  theme(
    axis.title = element_text(size = 10),
    axis.text = element_text(size = 9)
  )

# Figure C.8c: Percentage who wrote in favor of increased support (conditional on writing)
fig_c8c <- debt_w2 %>%
  filter(income_w2 < 88 & wroteF == 1) %>%
  mutate(income_bin = cut(income_w2, breaks = 5, labels = FALSE)) %>%
  group_by(income_bin) %>%
  summarise(
    income_mean = mean(income_w2, na.rm = TRUE),
    help_mean = mean(prioSupp, na.rm = TRUE),  # Changed from more_help_n_spending
    .groups = "drop"
  ) %>%
  ggplot(aes(x = income_mean, y = help_mean)) +
  geom_point(size = 3) +
  geom_smooth(method = "lm", se = TRUE, color = "blue", linewidth = 0.8) +
  scale_y_continuous(limits = c(0.3, 0.6), breaks = seq(0.3, 0.6, 0.1)) +
  labs(x = "Income", y = "% who wrote in favor of inc supp.") +
  theme_minimal() +
  theme(
    axis.title = element_text(size = 10),
    axis.text = element_text(size = 9)
  )

# Combine plots
fig_c8_combined <- fig_c8a | fig_c8b | fig_c8c

ggsave("appendix/FigureC8.pdf", fig_c8_combined, width = 15, height = 8)

```

# Appendix D  

## Table D.1: Regression tables for main results

```{r, results = 'asis', message=F, echo=FALSE}
# re-run regression models from figure 5
dd_debt_3 <- lm(debt_post_z_w1 ~ treat + as.factor(debt_pre_w1) + as.factor(block_w1), data = debt_w1)
dd_debt_2 <- lm(debt_post_z_w2 ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)
dd_debt_1 <- lm(debt_post_z_w3 ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2_w3)

dd_index_3 <- lm(debt_index_z_w1 ~ treat + as.factor(debt_pre_w1) + as.factor(block_w1), data = debt_w1)
dd_index_2 <- lm(debt_index_z_w2 ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)
dd_index_1 <- lm(debt_index_z_w3 ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2_w3)

dd_nhs_3 <- lm(debt_nhs_rec_w1 ~ treat + as.factor(debt_pre_w1) + as.factor(block_w1), data = debt_w1)
dd_nhs_2 <- lm(debt_nhs_rec_w2 ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)
dd_nhs_1 <- lm(debt_nhs_rec_w3 ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2_w3)

dd_cc_3 <- lm(debt_CC_rec_w1 ~ treat + as.factor(debt_pre_w1) + as.factor(block_w1), data = debt_w1)
dd_cc_2 <- lm(debt_CC_rec_w2 ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)
dd_cc_1 <- lm(debt_CC_rec_w3 ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2_w3)

dd_immi_3 <- lm(debt_immi_rec_w1 ~ treat + as.factor(debt_pre_w1) + as.factor(block_w1), data = debt_w1)
dd_immi_2 <- lm(debt_immi_rec_w2 ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)
dd_immi_1 <- lm(debt_immi_rec_w3 ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2_w3)

dd_infl_to_2 <- lm(debt_infl_rec_w2 ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)
dd_infl_to_1 <- lm(debt_infl_rec_w3 ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2_w3)

panels <- list(
  "Survey 1" = list(
    "Concern" = dd_debt_3,
    "Debt Aversion Index" = dd_index_3,
    "Debt vs. NHS" =  dd_nhs_3,
    "Debt vs. Climate Change" = dd_cc_3,
    "Debt vs. Immigration" = dd_immi_3
  ),
  "Survey 2, Wave 1" = list(
    "Concern" = dd_debt_2,
    "Debt Aversion Index" = dd_index_2,
      "Debt vs. NHS" =  dd_nhs_2,
    "Debt vs. Climate Change" = dd_cc_2,
    "Debt vs. Immigration" = dd_immi_2,
    "Debt vs. Inflation" = dd_infl_to_2
  ),
  "Survey 2, Wave 2" = list(
    "Concern" = dd_debt_1,
    "Debt Aversion Index" = dd_index_1,
   "Debt vs. NHS" =  dd_nhs_1,
    "Debt vs. Climate Change" = dd_cc_1,
    "Debt vs. Immigration" = dd_immi_1,
   "Debt vs. Inflation" = dd_infl_to_1
  )
)

gm <- c("r.squared", "adj.r.squared", "nobs")
regressions_ate <- modelsummary(
  panels,
  shape = "rbind",
  gof_map = gm, stars = TRUE, title="Regression table: Average treatment effects of video treatments on concern, debt aversion, and policy priorities", coef_omit = "as.factor", coef_rename = c("treat2" = "Sustainable", "treat3" = "Unsustainable"), output = "tinytable",  width = c(0.25, rep(0.18, 6))) 

# Apply styling
regressions_ate <- regressions_ate %>%
  style_tt(fontsize = 9)                                     # Font size

# Save
save_tt(regressions_ate, output = "appendix/TableD1.tex", overwrite = TRUE)
```

## Table D.2

```{r, results = 'asis', message=F, echo=FALSE}

# Regression models for allocation and behavioral outcomes
dd_alloc_3 <- lm(alloc_debt_z_w1 ~ treat + as.factor(debt_pre_w1) + as.factor(block_w1), data = debt_w1)
dd_alloc_2 <- lm(alloc_debt_z_w2 ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)
dd_qvsr_debt <- lm(qvsr_debt_z ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2_w3_qvsr)

dd3_wrote <- lm(wroteF ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)
dd2_prioDebt <- lm(prioDebt ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)
dd1_prioSupp <- lm(prioSupp ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)

panels <- list(
  "Survey Exercises" = list(
    "Higher debt (NHS exercise, Survey 1)" = dd_alloc_3,
    "Higher debt (NHS exercise, Survey 2)" = dd_alloc_2,
    "QVSR debt priority (Survey 2)" = dd_qvsr_debt
  ),
  "Letter-Writing Outcomes (Survey 2)" = list(
    "Wrote letter" = dd3_wrote,
    "Priority: Debt" = dd2_prioDebt,
    "Priority: Support" = dd1_prioSupp
  )
)

gm <- c("r.squared", "adj.r.squared", "nobs")

regressions_alloc_behav <- modelsummary(
  panels,
  shape = "rbind",
  gof_map = gm, 
  stars = TRUE, 
  title = "Regression table: Average treatment effects on allocation tasks and letter-writing outcomes", 
  coef_omit = "as.factor", 
  coef_rename = c("treat2" = "Sustainable", "treat3" = "Unsustainable"), 
  output = "tinytable",  
  width = c(0.25, rep(0.18, 3))
)

# Apply styling
regressions_alloc_behav <- regressions_alloc_behav %>%
  style_tt(fontsize = 9)

# Save
save_tt(regressions_alloc_behav, output = "appendix/TableD2.tex", overwrite = TRUE)
```

## Table D.3 - TOP PANEL

```{r, results = 'asis', message=F, echo=FALSE}
# Create matrix for results
create_table_d2_top <- function(df) {
  
# Initialize results matrix
  results <- matrix(0, nrow = 3, ncol = 6)
  colnames(results) <- c("Overall", "Left-wing", "Right-wing", 
                         "Overall", "Left-wing", "Right-wing")
  rownames(results) <- c("% prioDebt, Control",
                         "% prioDebt, Sustainable T",
                         "% prioDebt, Unsustainable T")

# By treatment (overall)
results[1, 1] <- df %>% filter(treat == 1) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
results[2, 1] <- df %>% filter(treat == 2) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
results[3, 1] <- df %>% filter(treat == 3) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)

# By treatment for left-wing voters
results[1, 2] <- df %>% filter(party_w2 == "Left-wing" & treat == 1) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
results[2, 2] <- df %>% filter(party_w2 == "Left-wing" & treat == 2) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
results[3, 2] <- df %>% filter(party_w2 == "Left-wing" & treat == 3) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
  
# By treatment for right-wing voters
results[1, 3] <- df %>% filter(party_w2 == "Right-wing" & treat == 1) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
results[2, 3] <- df %>% filter(party_w2 == "Right-wing" & treat == 2) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
results[3, 3] <- df %>% filter(party_w2 == "Right-wing" & treat == 3) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)

  # Conditional on wroteF == 1
debt_w2_wrote <- debt_w2 %>% filter(wroteF == 1)

# By treatment (wrote)
results[1, 4] <- debt_w2_wrote %>% filter(treat == 1) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
results[2, 4] <- debt_w2_wrote %>% filter(treat == 2) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
results[3, 4] <- debt_w2_wrote %>% filter(treat == 3) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)

  # By treatment for left-wing voters (wrote)
  results[1, 5] <- debt_w2_wrote %>% filter(party_w2 == "Left-wing" & treat == 1) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
  results[2, 5] <- debt_w2_wrote %>% filter(party_w2 == "Left-wing" & treat == 2) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
  results[3, 5] <- debt_w2_wrote %>% filter(party_w2 == "Left-wing" & treat == 3) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
  
  # By treatment for right-wing voters (wrote)
  results[1, 6] <- debt_w2_wrote %>% filter(party_w2 == "Right-wing" & treat == 1) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
  results[2, 6] <- debt_w2_wrote %>% filter(party_w2 == "Right-wing" & treat == 2) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
  results[3, 6] <- debt_w2_wrote %>% filter(party_w2 == "Right-wing" & treat == 3) %>% summarise(m = mean(prioDebt, na.rm = TRUE)) %>% pull(m)
  
  return(results)
}

table_d2_top <- create_table_d2_top(debt_w2)

# Export to LaTeX
kable(table_d2_top, format = "latex", digits = 2, booktabs = TRUE) %>%
  writeLines("appendix/TableD3_top.tex")
```

## Table D.3 - BOTTOM PANEL

```{r, results = 'asis', message=F, echo=FALSE}
# Create matrix for results
create_table_d2_bottom <- function(df) {
  
# Initialize results matrix
  results <- matrix(0, nrow = 3, ncol = 6)
  colnames(results) <- c("Overall", "Left-wing", "Right-wing",
                         "Overall", "Left-wing", "Right-wing")
  rownames(results) <- c("% prioSupp, Control",
                         "% prioSupp, Sustainable T",
                         "% prioSupp, Unsustainable T")

# By treatment (overall)
results[1, 1] <- df %>% filter(treat == 1) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
results[2, 1] <- df %>% filter(treat == 2) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
results[3, 1] <- df %>% filter(treat == 3) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)

# By treatment for left-wing voters
results[1, 2] <- df %>% filter(party_w2 == "Left-wing" & treat == 1) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
results[2, 2] <- df %>% filter(party_w2 == "Left-wing" & treat == 2) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
results[3, 2] <- df %>% filter(party_w2 == "Left-wing"& treat == 3) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
  
# By treatment for right-wing voters
results[1, 3] <- df %>% filter(party_w2 == "Right-wing" & treat == 1) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
results[2, 3] <- df %>% filter(party_w2 == "Right-wing" & treat == 2) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
results[3, 3] <- df %>% filter(party_w2 == "Right-wing" & treat == 3) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)

  # Conditional on wroteF == 1
debt_w2_wrote <- debt_w2 %>% filter(wroteF == 1)

# By treatment (wrote)
results[1, 4] <- debt_w2_wrote %>% filter(treat == 1) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
results[2, 4] <- debt_w2_wrote %>% filter(treat == 2) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
results[3, 4] <- debt_w2_wrote %>% filter(treat == 3) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)

  # By treatment for left-wing voters (wrote)
  results[1, 5] <- debt_w2_wrote %>% filter(party_w2 == "Left-wing" & treat == 1) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
  results[2, 5] <- debt_w2_wrote %>% filter(party_w2 == "Left-wing" & treat == 2) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
  results[3, 5] <- debt_w2_wrote %>% filter(party_w2 == "Left-wing" & treat == 3) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
  
  # By treatment for right-wing voters (wrote)
  results[1, 6] <- debt_w2_wrote %>% filter(party_w2 == "Right-wing" & treat == 1) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
  results[2, 6] <- debt_w2_wrote %>% filter(party_w2 == "Right-wing" & treat == 2) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
  results[3, 6] <- debt_w2_wrote %>% filter(party_w2 == "Right-wing" & treat == 3) %>% summarise(m = mean(prioSupp, na.rm = TRUE)) %>% pull(m)
  
  return(results)
}

table_d2_bottom <- create_table_d2_bottom(debt_w2)

# Export to LaTeX
kable(table_d2_bottom, format = "latex", digits = 2, booktabs = TRUE) %>%
  writeLines("appendix/TableD3_bottom.tex")
```

# Appendix E:

## Table E.1

```{r, results = 'asis', message=F, echo=FALSE}
# re-run regression models from Figure 7
## average treatment effect on expectations for nhs (quality)
debt_w1$exp_nhs_qual_w1 <- as.numeric(debt_w1$exp_nhs_qual_w1)
debt_w2$exp_nhs_qual_w2 <- as.numeric(debt_w2$exp_nhs_qual_w2)

# standardize variables
debt_w1 <- debt_w1 %>% 
  mutate(exp_nhs_qual_w1_z = as.vector(scale(exp_nhs_qual_w1)))
debt_w2 <- debt_w2 %>% 
  mutate(exp_nhs_qual_w2_z = as.vector(scale(exp_nhs_qual_w2)))

dd_nhs_qual_2 <- lm(exp_nhs_qual_w1_z ~ treat + as.factor(debt_pre_w1) + as.factor(block_w1), data = debt_w1)
dd_nhs_qual_1 <- lm(exp_nhs_qual_w2_z ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)

## average treatment effects on expectations for the nhs (costs)
debt_w1$exp_nhs_costs_w1 <- as.numeric(debt_w1$exp_nhs_costs_w1)
debt_w2$exp_nhs_costs_w2 <- as.numeric(debt_w2$exp_nhs_costs_w2)

# standardize variables
debt_w1 <- debt_w1 %>% 
  mutate(exp_nhs_costs_w1_z = as.vector(scale(exp_nhs_costs_w1)))
debt_w2 <- debt_w2 %>% 
  mutate(exp_nhs_costs_w2_z = as.vector(scale(exp_nhs_costs_w2)))

dd_nhs_costs_2 <- lm(exp_nhs_costs_w1_z ~ treat + as.factor(debt_pre_w1) + as.factor(block_w1), data = debt_w1)
dd_nhs_costs_1 <- lm(exp_nhs_costs_w2_z ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)

## average treatment effect on growth expectations
debt_w1$exp_gdp_w1 <- as.numeric(debt_w1$exp_gdp_w1)
debt_w2$exp_gdp_w2 <- as.numeric(debt_w2$exp_gdp_w2)

# standardize variables
debt_w1 <- debt_w1 %>% 
  mutate(exp_gdp_w1_z = as.vector(scale(exp_gdp_w1)))
debt_w2 <- debt_w2 %>% 
  mutate(exp_gdp_w2_z = as.vector(scale(exp_gdp_w2)))

dd_gdp_2 <- lm(exp_gdp_w1_z ~ treat + as.factor(debt_pre_w1) + as.factor(block_w1), data = debt_w1)
dd_gdp_1 <- lm(exp_gdp_w2_z ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)

## average treatment effect on inflation expectations
debt_w1$exp_infl_w1 <- as.numeric(debt_w1$exp_infl_w1)
debt_w2$exp_infl_w2 <- as.numeric(debt_w2$exp_infl_w2)

# standardize variables
debt_w1 <- debt_w1 %>% 
  mutate(exp_infl_w1_z = as.vector(scale(exp_infl_w1)))
debt_w2 <- debt_w2 %>% 
  mutate(exp_infl_w2_z = as.vector(scale(exp_infl_w2)))

dd_infl_2 <- lm(exp_infl_w1_z ~ treat + as.factor(debt_pre_w1) + as.factor(block_w1), data = debt_w1)
dd_infl_1 <- lm(exp_infl_w2_z ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)

## average treatment effect on tax expectation 
debt_w1$exp_tax_w1 <- as.numeric(debt_w1$exp_tax_w1)
debt_w2$exp_tax_w2 <- as.numeric(debt_w2$exp_tax_w2)

# standardize variables
debt_w1 <- debt_w1 %>% 
  mutate(exp_tax_w1_z = as.vector(scale(exp_tax_w1)))
debt_w2 <- debt_w2 %>% 
  mutate(exp_tax_w2_z = as.vector(scale(exp_tax_w2)))

dd_tax_2 <- lm(exp_tax_w1_z ~ treat + as.factor(debt_pre_w1) + as.factor(block_w1), data = debt_w1)
dd_tax_1 <- lm(exp_tax_w2_z ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)

## average treatment effect on pension expectations
debt_w1$exp_pen_w1 <- as.numeric(debt_w1$exp_pen_w1)
debt_w2$exp_pen_w2 <- as.numeric(debt_w2$exp_pen_w2)

# standardize variables
debt_w1 <- debt_w1 %>% 
  mutate(exp_pen_w1_z = as.vector(scale(exp_pen_w1)))
debt_w2 <- debt_w2 %>% 
  mutate(exp_pen_w2_z = as.vector(scale(exp_pen_w2)))

dd_pen_2 <- lm(exp_pen_w1_z ~ treat + as.factor(debt_pre_w1) + as.factor(block_w1), data = debt_w1)
dd_pen_1 <- lm(exp_pen_w2_z ~ treat + as.factor(debt_pre_w2) + as.factor(block_w2), data = debt_w2)

panels <- list(
  "Survey 1" = list(
    "Taxes" =  dd_tax_2,
    "Pensions"= dd_pen_2,
    "NHS (Quality)" = dd_nhs_qual_2,
    "NHS (Costs)" = dd_nhs_costs_2,
    "GDP" =  dd_gdp_2,
    "Inflation" =  dd_infl_2
  ),
  "Survey 2, wave 1" = list(
    "Taxes" =  dd_tax_1,
    "Pensions"= dd_pen_1,
    "NHS (Quality)" = dd_nhs_qual_1,
    "NHS (Costs)" = dd_nhs_costs_1,
    "GDP" =  dd_gdp_1,
    "Inflation" =  dd_infl_1
  )
)

regressions_exp <- modelsummary(
  panels,
  shape = "rbind",
  gof_map = gm, 
  stars = TRUE, 
  title = "Regression table: Average treatment effects on expectations", 
  coef_omit = "as.factor", 
  coef_rename = c("treat2" = "Sustainable", "treat3" = "Unsustainable"), 
  output = "tinytable",
  width = c(0.25, rep(0.18, 6))
)

# Apply styling
regressions_exp <- regressions_exp %>%
  style_tt(fontsize = 9)

save_tt(regressions_exp, output = "appendix/TableE1.tex", overwrite = TRUE)
```

# Appendix F 

## Figure F.1: HTE by partisanship

```{r, results = 'asis', message=F, echo=FALSE}
# analyze effect of treatment on concern
dd_debt_part_w1 <- lm(debt_post_z_w1 ~ treat*party_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_debt_part_ma_w1 <- margins::margins(dd_debt_part_w1, variables = "treat", at = list(party_rec_w1 = c("Labour", "Conservatives")))
ame_dd_debt_part_w1 <- as.data.frame(summary(dd_debt_part_ma_w1))
ame_dd_debt_part_w1$party_rec_w1 <- as.character(ame_dd_debt_part_w1$party_rec_w1)
ame_dd_debt_part_w1$AME <- as.numeric(ame_dd_debt_part_w1$AME)
ame_dd_debt_part_w1$SE <- as.numeric(ame_dd_debt_part_w1$SE)
ame_dd_debt_part_w1$Treatment <- ame_dd_debt_part_w1$factor
ame_dd_debt_part_w1$upper95 <- ame_dd_debt_part_w1$AME + (ame_dd_debt_part_w1$SE*1.96)
ame_dd_debt_part_w1$lower95 <- ame_dd_debt_part_w1$AME - (ame_dd_debt_part_w1$SE*1.96)

ame_dd_debt_part_w1$Treatment[ame_dd_debt_part_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_debt_part_w1$Treatment[ame_dd_debt_part_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_debt_part_w1$party_rec_w1 <- factor(ame_dd_debt_part_w1$party_rec_w1, levels = c("Labour", "Conservatives"))

gg_ame_dd_debt_part_w1 <- ggplot(ame_dd_debt_part_w1, aes(colour = party_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) +
  geom_point(aes(y = Treatment, x=AME, shape = party_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_fill_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_shape_discrete("Partisanship", breaks=c("Labour", "Conservatives")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-1,1) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Concern") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt aversion index
dd_index_part_w1 <- lm(debt_index_z_w1 ~ treat*party_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_index_part_ma_w1 <- margins::margins(dd_index_part_w1, variables = "treat", at = list(party_rec_w1 = c("Labour", "Conservatives")))
ame_dd_index_part_w1 <- as.data.frame(summary(dd_index_part_ma_w1))
ame_dd_index_part_w1$party_rec_w1 <- as.character(ame_dd_index_part_w1$party_rec_w1)
ame_dd_index_part_w1$AME <- as.numeric(ame_dd_index_part_w1$AME)
ame_dd_index_part_w1$SE <- as.numeric(ame_dd_index_part_w1$SE)
ame_dd_index_part_w1$Treatment <- ame_dd_index_part_w1$factor
ame_dd_index_part_w1$upper95 <- ame_dd_index_part_w1$AME + (ame_dd_index_part_w1$SE*1.96)
ame_dd_index_part_w1$lower95 <- ame_dd_index_part_w1$AME - (ame_dd_index_part_w1$SE*1.96)

ame_dd_index_part_w1$Treatment[ame_dd_index_part_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_index_part_w1$Treatment[ame_dd_index_part_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_index_part_w1$party_rec_w1 <- factor(ame_dd_index_part_w1$party_rec_w1, levels = c("Labour", "Conservatives"))

gg_ame_dd_index_part_w1 <- ggplot(ame_dd_index_part_w1, aes(colour = party_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) +
  geom_point(aes(y = Treatment, x=AME, shape = party_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_fill_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_shape_discrete("Partisanship", breaks=c("Labour", "Conservatives")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-1,1) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt Aversion Index") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. NHS
dd_nhs_part_w1 <- lm(debt_nhs_rec_w1 ~ treat*party_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_nhs_part_ma_w1 <- margins::margins(dd_nhs_part_w1, variables = "treat", at = list(party_rec_w1 = c("Labour", "Conservatives")))
ame_dd_nhs_part_w1 <- as.data.frame(summary(dd_nhs_part_ma_w1))
ame_dd_nhs_part_w1$party_rec_w1 <- as.character(ame_dd_nhs_part_w1$party_rec_w1)
ame_dd_nhs_part_w1$AME <- as.numeric(ame_dd_nhs_part_w1$AME)
ame_dd_nhs_part_w1$SE <- as.numeric(ame_dd_nhs_part_w1$SE)
ame_dd_nhs_part_w1$Treatment <- ame_dd_nhs_part_w1$factor
ame_dd_nhs_part_w1$upper95 <- ame_dd_nhs_part_w1$AME + (ame_dd_nhs_part_w1$SE*1.96)
ame_dd_nhs_part_w1$lower95 <- ame_dd_nhs_part_w1$AME - (ame_dd_nhs_part_w1$SE*1.96)

ame_dd_nhs_part_w1$Treatment[ame_dd_nhs_part_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_nhs_part_w1$Treatment[ame_dd_nhs_part_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_nhs_part_w1 <- ggplot(ame_dd_nhs_part_w1, aes(colour = party_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = party_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("") + 
  scale_fill_grey("") + 
  scale_shape_discrete("") +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. NHS") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. climate change
dd_cc_part_w1 <- lm(debt_CC_rec_w1 ~ treat*party_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_cc_part_ma_w1 <- margins::margins(dd_cc_part_w1, variables = "treat", at = list(party_rec_w1 = c("Labour", "Conservatives")))
ame_dd_cc_part_w1 <- as.data.frame(summary(dd_cc_part_ma_w1))
ame_dd_cc_part_w1$party_rec_w1 <- as.character(ame_dd_cc_part_w1$party_rec_w1)
ame_dd_cc_part_w1$AME <- as.numeric(ame_dd_cc_part_w1$AME)
ame_dd_cc_part_w1$SE <- as.numeric(ame_dd_cc_part_w1$SE)
ame_dd_cc_part_w1$Treatment <- ame_dd_cc_part_w1$factor
ame_dd_cc_part_w1$upper95 <- ame_dd_cc_part_w1$AME + (ame_dd_cc_part_w1$SE*1.96)
ame_dd_cc_part_w1$lower95 <- ame_dd_cc_part_w1$AME - (ame_dd_cc_part_w1$SE*1.96)

ame_dd_cc_part_w1$Treatment[ame_dd_cc_part_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_cc_part_w1$Treatment[ame_dd_cc_part_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_cc_part_w1 <- ggplot(ame_dd_cc_part_w1, aes(colour = party_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = party_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("") + 
  scale_fill_grey("") + 
  scale_shape_discrete("") +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. Climate Change") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. immigration
dd_immi_part_w1 <- lm(debt_immi_rec_w1 ~ treat*party_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_immi_part_ma_w1 <- margins::margins(dd_immi_part_w1, variables = "treat", at = list(party_rec_w1 = c("Labour", "Conservatives")))
ame_dd_immi_part_w1 <- as.data.frame(summary(dd_immi_part_ma_w1))
ame_dd_immi_part_w1$party_rec_w1 <- as.character(ame_dd_immi_part_w1$party_rec_w1)
ame_dd_immi_part_w1$AME <- as.numeric(ame_dd_immi_part_w1$AME)
ame_dd_immi_part_w1$SE <- as.numeric(ame_dd_immi_part_w1$SE)
ame_dd_immi_part_w1$Treatment <- ame_dd_immi_part_w1$factor
ame_dd_immi_part_w1$upper95 <- ame_dd_immi_part_w1$AME + (ame_dd_immi_part_w1$SE*1.96)
ame_dd_immi_part_w1$lower95 <- ame_dd_immi_part_w1$AME - (ame_dd_immi_part_w1$SE*1.96)

ame_dd_immi_part_w1$Treatment[ame_dd_immi_part_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_immi_part_w1$Treatment[ame_dd_immi_part_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_immi_part_w1 <- ggplot(ame_dd_immi_part_w1, aes(colour = party_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = party_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("") + 
  scale_fill_grey("") + 
  scale_shape_discrete("") +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. Immigration") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. inflation
dd_infl_part_w2 <- lm(debt_infl_rec_w2 ~ treat*party_rec_w2 + as.factor(debt_pre_w2), data = debt_w2)
dd_infl_part_ma_w2 <- margins::margins(dd_infl_part_w2, variables = "treat", at = list(party_rec_w2 = c("Labour", "Conservatives")))
ame_dd_infl_part_w2 <- as.data.frame(summary(dd_infl_part_ma_w2))
ame_dd_infl_part_w2$party_rec_w2 <- as.character(ame_dd_infl_part_w2$party_rec_w2)
ame_dd_infl_part_w2$AME <- as.numeric(ame_dd_infl_part_w2$AME)
ame_dd_infl_part_w2$SE <- as.numeric(ame_dd_infl_part_w2$SE)
ame_dd_infl_part_w2$Treatment <- ame_dd_infl_part_w2$factor
ame_dd_infl_part_w2$upper95 <- ame_dd_infl_part_w2$AME + (ame_dd_infl_part_w2$SE*1.96)
ame_dd_infl_part_w2$lower95 <- ame_dd_infl_part_w2$AME - (ame_dd_infl_part_w2$SE*1.96)

ame_dd_infl_part_w2$Treatment[ame_dd_infl_part_w2$Treatment=="treat2"] <- "Sustainable"
ame_dd_infl_part_w2$Treatment[ame_dd_infl_part_w2$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_infl_part_w2 <- ggplot(ame_dd_infl_part_w2, aes(colour = party_rec_w2)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = party_rec_w2), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("") + 
  scale_fill_grey("") + 
  scale_shape_discrete("") +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. Inflation") + 
      theme(plot.title = element_text(face = "bold"))

ate_hte_graph_w1 <- ggarrange(gg_ame_dd_debt_part_w1, 
                              gg_ame_dd_index_part_w1 + 
                             theme(axis.text.y = element_blank(),
                                   axis.title.y = element_blank()), 
                              gg_ame_dd_cc_part_w1,
                              gg_ame_dd_immi_part_w1 + 
                             theme(axis.text.y = element_blank(),
                                   axis.title.y = element_blank()),
                              gg_ame_dd_nhs_part_w1, 
                              gg_ame_dd_infl_part_w2 + 
                             theme(axis.text.y = element_blank(),
                                   axis.title.y = element_blank()), 
                             nrow=3, ncol=2, common.legend = T,  legend="bottom",
                             widths = c(1, 0.75))
ate_hte_graph_w1

ggsave(ate_hte_graph_w1, width = 18, height = 20, units = c("cm"), file ="appendix/FigureF1.pdf")
```

## Figure F2: Partisanship (expectations)

```{r, results = 'asis', message=F, echo=FALSE}
# analyze effect of treatment on nhs quality
dd_nhs_qual_party_w1 <- lm(exp_nhs_qual_w1_z ~ treat*party_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_nhs_qual_party_ma_w1 <- margins::margins(dd_nhs_qual_party_w1, variables = "treat", at = list(party_rec_w1 = c("Labour", "Conservatives")))
ame_dd_nhs_qual_party_w1 <- as.data.frame(summary(dd_nhs_qual_party_ma_w1))
ame_dd_nhs_qual_party_w1$party_rec_w1 <- as.character(ame_dd_nhs_qual_party_w1$party_rec_w1)
ame_dd_nhs_qual_party_w1$AME <- as.numeric(ame_dd_nhs_qual_party_w1$AME)
ame_dd_nhs_qual_party_w1$SE <- as.numeric(ame_dd_nhs_qual_party_w1$SE)
ame_dd_nhs_qual_party_w1$Treatment <- ame_dd_nhs_qual_party_w1$factor
ame_dd_nhs_qual_party_w1$upper95 <- ame_dd_nhs_qual_party_w1$AME + (ame_dd_nhs_qual_party_w1$SE*1.96)
ame_dd_nhs_qual_party_w1$lower95 <- ame_dd_nhs_qual_party_w1$AME - (ame_dd_nhs_qual_party_w1$SE*1.96)

ame_dd_nhs_qual_party_w1$Treatment[ame_dd_nhs_qual_party_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_nhs_qual_party_w1$Treatment[ame_dd_nhs_qual_party_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_nhs_qual_party_w1$party_rec_w1 <- factor(ame_dd_nhs_qual_party_w1$party_rec_w1, levels = c("Labour", "Conservatives"))

gg_ame_dd_nhs_qual_party_w1 <- ggplot(ame_dd_nhs_qual_party_w1, aes(colour = party_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = party_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_fill_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_shape_discrete("Partisanship", breaks=c("Labour", "Conservatives")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("NHS (Quality)") + 
      theme(plot.title = element_text(face = "bold"))


# analyze effect of treatment on nhs costs
dd_nhs_costs_party_w1 <- lm(exp_nhs_costs_w1_z ~ treat*party_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_nhs_costs_party_ma_w1 <- margins::margins(dd_nhs_costs_party_w1, variables = "treat", at = list(party_rec_w1 = c("Labour", "Conservatives")))
ame_dd_nhs_costs_party_w1 <- as.data.frame(summary(dd_nhs_costs_party_ma_w1))
ame_dd_nhs_costs_party_w1$party_rec_w1 <- as.character(ame_dd_nhs_costs_party_w1$party_rec_w1)
ame_dd_nhs_costs_party_w1$AME <- as.numeric(ame_dd_nhs_costs_party_w1$AME)
ame_dd_nhs_costs_party_w1$SE <- as.numeric(ame_dd_nhs_costs_party_w1$SE)
ame_dd_nhs_costs_party_w1$Treatment <- ame_dd_nhs_costs_party_w1$factor
ame_dd_nhs_costs_party_w1$upper95 <- ame_dd_nhs_costs_party_w1$AME + (ame_dd_nhs_costs_party_w1$SE*1.96)
ame_dd_nhs_costs_party_w1$lower95 <- ame_dd_nhs_costs_party_w1$AME - (ame_dd_nhs_costs_party_w1$SE*1.96)

ame_dd_nhs_costs_party_w1$Treatment[ame_dd_nhs_costs_party_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_nhs_costs_party_w1$Treatment[ame_dd_nhs_costs_party_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_nhs_costs_party_w1$party_rec_w1 <- factor(ame_dd_nhs_costs_party_w1$party_rec_w1, levels = c("Labour", "Conservatives"))

gg_ame_dd_nhs_costs_party_w1 <- ggplot(ame_dd_nhs_costs_party_w1, aes(colour = party_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = party_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_fill_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_shape_discrete("Partisanship", breaks=c("Labour", "Conservatives")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("NHS (Costs)") + 
      theme(plot.title = element_text(face = "bold"))


# analyze effect of treatment on GDP expectation
dd_gdp_party_w1 <- lm(exp_gdp_w1_z ~ treat*party_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_gdp_party_ma_w1 <- margins::margins(dd_gdp_party_w1, variables = "treat", at = list(party_rec_w1 = c("Labour", "Conservatives")))
ame_dd_gdp_party_w1 <- as.data.frame(summary(dd_gdp_party_ma_w1))
ame_dd_gdp_party_w1$party_rec_w1 <- as.character(ame_dd_gdp_party_w1$party_rec_w1)
ame_dd_gdp_party_w1$AME <- as.numeric(ame_dd_gdp_party_w1$AME)
ame_dd_gdp_party_w1$SE <- as.numeric(ame_dd_gdp_party_w1$SE)
ame_dd_gdp_party_w1$Treatment <- ame_dd_gdp_party_w1$factor
ame_dd_gdp_party_w1$upper95 <- ame_dd_gdp_party_w1$AME + (ame_dd_gdp_party_w1$SE*1.96)
ame_dd_gdp_party_w1$lower95 <- ame_dd_gdp_party_w1$AME - (ame_dd_gdp_party_w1$SE*1.96)

ame_dd_gdp_party_w1$Treatment[ame_dd_gdp_party_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_gdp_party_w1$Treatment[ame_dd_gdp_party_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_gdp_party_w1$party_rec_w1 <- factor(ame_dd_gdp_party_w1$party_rec_w1, levels = c("Labour", "Conservatives"))

gg_ame_dd_gdp_party_w1 <- ggplot(ame_dd_gdp_party_w1, aes(colour = party_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = party_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_fill_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_shape_discrete("Partisanship", breaks=c("Labour", "Conservatives")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +       xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("GDP") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on inflation expectation
dd_infl_party_w1 <- lm(exp_infl_w1_z ~ treat*party_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_infl_party_ma_w1 <- margins::margins(dd_infl_party_w1, variables = "treat", at = list(party_rec_w1 = c("Labour", "Conservatives")))
ame_dd_infl_party_w1 <- as.data.frame(summary(dd_infl_party_ma_w1))
ame_dd_infl_party_w1$party_rec_w1 <- as.character(ame_dd_infl_party_w1$party_rec_w1)
ame_dd_infl_party_w1$AME <- as.numeric(ame_dd_infl_party_w1$AME)
ame_dd_infl_party_w1$SE <- as.numeric(ame_dd_infl_party_w1$SE)
ame_dd_infl_party_w1$Treatment <- ame_dd_infl_party_w1$factor
ame_dd_infl_party_w1$upper95 <- ame_dd_infl_party_w1$AME + (ame_dd_infl_party_w1$SE*1.96)
ame_dd_infl_party_w1$lower95 <- ame_dd_infl_party_w1$AME - (ame_dd_infl_party_w1$SE*1.96)

ame_dd_infl_party_w1$Treatment[ame_dd_infl_party_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_infl_party_w1$Treatment[ame_dd_infl_party_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_infl_party_w1$party_rec_w1 <- factor(ame_dd_infl_party_w1$party_rec_w1, levels = c("Labour", "Conservatives"))

gg_ame_dd_infl_party_w1 <- ggplot(ame_dd_infl_party_w1, aes(colour = party_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = party_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_fill_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_shape_discrete("Partisanship", breaks=c("Labour", "Conservatives")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +       xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Inflation") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on taxes
dd_tax_party_w1 <- lm(exp_tax_w1_z ~ treat*party_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_tax_party_ma_w1 <- margins::margins(dd_tax_party_w1, variables = "treat", at = list(party_rec_w1 = c("Labour", "Conservatives")))
ame_dd_tax_party_w1 <- as.data.frame(summary(dd_tax_party_ma_w1))
ame_dd_tax_party_w1$party_rec_w1 <- as.character(ame_dd_tax_party_w1$party_rec_w1)
ame_dd_tax_party_w1$AME <- as.numeric(ame_dd_tax_party_w1$AME)
ame_dd_tax_party_w1$SE <- as.numeric(ame_dd_tax_party_w1$SE)
ame_dd_tax_party_w1$Treatment <- ame_dd_tax_party_w1$factor
ame_dd_tax_party_w1$upper95 <- ame_dd_tax_party_w1$AME + (ame_dd_tax_party_w1$SE*1.96)
ame_dd_tax_party_w1$lower95 <- ame_dd_tax_party_w1$AME - (ame_dd_tax_party_w1$SE*1.96)

ame_dd_tax_party_w1$Treatment[ame_dd_tax_party_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_tax_party_w1$Treatment[ame_dd_tax_party_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_tax_party_w1$party_rec_w1 <- factor(ame_dd_tax_party_w1$party_rec_w1, levels = c("Labour", "Conservatives"))

gg_ame_dd_tax_party_w1 <- ggplot(ame_dd_tax_party_w1, aes(colour = party_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = party_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_fill_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_shape_discrete("Partisanship", breaks=c("Labour", "Conservatives")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +       xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Taxes") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on pension
dd_pen_party_w1 <- lm(exp_pen_w1_z ~ treat*party_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_pen_party_ma_w1 <- margins::margins(dd_pen_party_w1, variables = "treat", at = list(party_rec_w1 = c("Labour", "Conservatives")))
ame_dd_pen_party_w1 <- as.data.frame(summary(dd_pen_party_ma_w1))
ame_dd_pen_party_w1$party_rec_w1 <- as.character(ame_dd_pen_party_w1$party_rec_w1)
ame_dd_pen_party_w1$AME <- as.numeric(ame_dd_pen_party_w1$AME)
ame_dd_pen_party_w1$SE <- as.numeric(ame_dd_pen_party_w1$SE)
ame_dd_pen_party_w1$Treatment <- ame_dd_pen_party_w1$factor
ame_dd_pen_party_w1$upper95 <- ame_dd_pen_party_w1$AME + (ame_dd_pen_party_w1$SE*1.96)
ame_dd_pen_party_w1$lower95 <- ame_dd_pen_party_w1$AME - (ame_dd_pen_party_w1$SE*1.96)

ame_dd_pen_party_w1$Treatment[ame_dd_pen_party_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_pen_party_w1$Treatment[ame_dd_pen_party_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_pen_party_w1$party_rec_w1 <- factor(ame_dd_pen_party_w1$party_rec_w1, levels = c("Labour", "Conservatives"))

gg_ame_dd_pen_party_w1 <- ggplot(ame_dd_pen_party_w1, aes(colour = party_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = party_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_fill_grey("Partisanship", breaks=c("Labour", "Conservatives")) + 
  scale_shape_discrete("Partisanship", breaks=c("Labour", "Conservatives")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
  scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Pensions") + 
      theme(plot.title = element_text(face = "bold"))

exp_hte_graph_party_w1 <- ggarrange(gg_ame_dd_tax_party_w1, 
                                    gg_ame_dd_pen_party_w1 + 
                                          theme(axis.text.y = element_blank(),
                                                axis.title.y = element_blank()), 
                                    gg_ame_dd_nhs_qual_party_w1, 
                                    gg_ame_dd_nhs_costs_party_w1 + 
                                          theme(axis.text.y = element_blank(),
                                                axis.title.y = element_blank()), 
                                    gg_ame_dd_gdp_party_w1, 
                                    gg_ame_dd_infl_party_w1 + 
                                          theme(axis.text.y = element_blank(),
                                                axis.title.y = element_blank()), nrow=3, ncol=2, common.legend = T,  legend="bottom", widths = c(1, 0.75))
exp_hte_graph_party_w1

ggsave(exp_hte_graph_party_w1, width = 18, height = 20, units = c("cm"), file ="appendix/FigureF2.pdf")
```


## Figure F.3: Education

```{r, results = 'asis', message=F, echo=FALSE}
# concern
dd_debt_edu_w1 <- lm(debt_post_z_w1 ~ treat*edu_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_debt_edu_ma_w1 <- margins::margins(dd_debt_edu_w1, variables = "treat", at = list(edu_rec_w1 = c("Low", "Middle", "High")))
ame_dd_debt_edu_w1 <- as.data.frame(summary(dd_debt_edu_ma_w1))
ame_dd_debt_edu_w1$edu_rec_w1 <- as.character(ame_dd_debt_edu_w1$edu_rec_w1)
ame_dd_debt_edu_w1$AME <- as.numeric(ame_dd_debt_edu_w1$AME)
ame_dd_debt_edu_w1$SE <- as.numeric(ame_dd_debt_edu_w1$SE)
ame_dd_debt_edu_w1$Treatment <- ame_dd_debt_edu_w1$factor
ame_dd_debt_edu_w1$upper95 <- ame_dd_debt_edu_w1$AME + (ame_dd_debt_edu_w1$SE*1.96)
ame_dd_debt_edu_w1$lower95 <- ame_dd_debt_edu_w1$AME - (ame_dd_debt_edu_w1$SE*1.96)

ame_dd_debt_edu_w1$Treatment[ame_dd_debt_edu_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_debt_edu_w1$Treatment[ame_dd_debt_edu_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_debt_edu_w1$edu_rec_w1 <- factor(ame_dd_debt_edu_w1$edu_rec_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_debt_edu_w1 <- ggplot(ame_dd_debt_edu_w1, aes(colour = edu_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = edu_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Education", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
  xlim(-1.05, 1.05) +
  xlab("Average treatment effect") +
  theme(legend.position="bottom") +
  theme(legend.position="bottom") + ggtitle("Concern") + 
  theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt index
dd_index_edu_w1 <- lm(debt_index_z_w1 ~ treat*edu_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_index_edu_ma_w1 <- margins::margins(dd_index_edu_w1, variables = "treat", at = list(edu_rec_w1 = c("Low", "Middle", "High")))
ame_dd_index_edu_w1 <- as.data.frame(summary(dd_index_edu_ma_w1))
ame_dd_index_edu_w1$edu_rec_w1 <- as.character(ame_dd_index_edu_w1$edu_rec_w1)
ame_dd_index_edu_w1$AME <- as.numeric(ame_dd_index_edu_w1$AME)
ame_dd_index_edu_w1$SE <- as.numeric(ame_dd_index_edu_w1$SE)
ame_dd_index_edu_w1$Treatment <- ame_dd_index_edu_w1$factor
ame_dd_index_edu_w1$upper95 <- ame_dd_index_edu_w1$AME + (ame_dd_index_edu_w1$SE*1.96)
ame_dd_index_edu_w1$lower95 <- ame_dd_index_edu_w1$AME - (ame_dd_index_edu_w1$SE*1.96)

ame_dd_index_edu_w1$Treatment[ame_dd_index_edu_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_index_edu_w1$Treatment[ame_dd_index_edu_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_index_edu_w1$edu_rec_w1 <- factor(ame_dd_index_edu_w1$edu_rec_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_index_edu_w1 <- ggplot(ame_dd_index_edu_w1, aes(colour = edu_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = edu_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Education", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-1.05, 1.05) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt Aversion Index") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. NHS
dd_nhs_edu_w1 <- lm(debt_nhs_rec_w1 ~ treat*edu_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_nhs_edu_ma_w1 <- margins::margins(dd_nhs_edu_w1, variables = "treat", at = list(edu_rec_w1 = c("Low", "Middle", "High")))
ame_dd_nhs_edu_w1 <- as.data.frame(summary(dd_nhs_edu_ma_w1))
ame_dd_nhs_edu_w1$edu_rec_w1 <- as.character(ame_dd_nhs_edu_w1$edu_rec_w1)
ame_dd_nhs_edu_w1$AME <- as.numeric(ame_dd_nhs_edu_w1$AME)
ame_dd_nhs_edu_w1$SE <- as.numeric(ame_dd_nhs_edu_w1$SE)
ame_dd_nhs_edu_w1$Treatment <- ame_dd_nhs_edu_w1$factor
ame_dd_nhs_edu_w1$upper95 <- ame_dd_nhs_edu_w1$AME + (ame_dd_nhs_edu_w1$SE*1.96)
ame_dd_nhs_edu_w1$lower95 <- ame_dd_nhs_edu_w1$AME - (ame_dd_nhs_edu_w1$SE*1.96)

ame_dd_nhs_edu_w1$Treatment[ame_dd_nhs_edu_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_nhs_edu_w1$Treatment[ame_dd_nhs_edu_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_nhs_edu_w1 <- ggplot(ame_dd_nhs_edu_w1, aes(colour = edu_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = edu_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Education", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. NHS") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. climate change
dd_cc_edu_w1 <- lm(debt_CC_rec_w1 ~ treat*edu_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_cc_edu_ma_w1 <- margins::margins(dd_cc_edu_w1, variables = "treat", at = list(edu_rec_w1 = c("Low", "Middle", "High")))
ame_dd_cc_edu_w1 <- as.data.frame(summary(dd_cc_edu_ma_w1))
ame_dd_cc_edu_w1$edu_rec_w1 <- as.character(ame_dd_cc_edu_w1$edu_rec_w1)
ame_dd_cc_edu_w1$AME <- as.numeric(ame_dd_cc_edu_w1$AME)
ame_dd_cc_edu_w1$SE <- as.numeric(ame_dd_cc_edu_w1$SE)
ame_dd_cc_edu_w1$Treatment <- ame_dd_cc_edu_w1$factor
ame_dd_cc_edu_w1$upper95 <- ame_dd_cc_edu_w1$AME + (ame_dd_cc_edu_w1$SE*1.96)
ame_dd_cc_edu_w1$lower95 <- ame_dd_cc_edu_w1$AME - (ame_dd_cc_edu_w1$SE*1.96)

ame_dd_cc_edu_w1$Treatment[ame_dd_cc_edu_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_cc_edu_w1$Treatment[ame_dd_cc_edu_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_cc_edu_w1 <- ggplot(ame_dd_cc_edu_w1, aes(colour = edu_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = edu_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Education", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. Climate Change") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. immigration
dd_immi_edu_w1 <- lm(debt_immi_rec_w1 ~ treat*edu_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_immi_edu_ma_w1 <- margins::margins(dd_immi_edu_w1, variables = "treat", at = list(edu_rec_w1 = c("Low", "Middle", "High")))
ame_dd_immi_edu_w1 <- as.data.frame(summary(dd_immi_edu_ma_w1))
ame_dd_immi_edu_w1$edu_rec_w1 <- as.character(ame_dd_immi_edu_w1$edu_rec_w1)
ame_dd_immi_edu_w1$AME <- as.numeric(ame_dd_immi_edu_w1$AME)
ame_dd_immi_edu_w1$SE <- as.numeric(ame_dd_immi_edu_w1$SE)
ame_dd_immi_edu_w1$Treatment <- ame_dd_immi_edu_w1$factor
ame_dd_immi_edu_w1$upper95 <- ame_dd_immi_edu_w1$AME + (ame_dd_immi_edu_w1$SE*1.96)
ame_dd_immi_edu_w1$lower95 <- ame_dd_immi_edu_w1$AME - (ame_dd_immi_edu_w1$SE*1.96)

ame_dd_immi_edu_w1$Treatment[ame_dd_immi_edu_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_immi_edu_w1$Treatment[ame_dd_immi_edu_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_immi_edu_w1 <- ggplot(ame_dd_immi_edu_w1, aes(colour = edu_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = edu_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Education", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. Immigration") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. inflation
dd_infl_edu_w2 <- lm(debt_infl_rec_w2 ~ treat*edu_rec_w2 + as.factor(debt_pre_w2), data = debt_w2)
dd_infl_edu_ma_w2 <- margins::margins(dd_infl_edu_w2, variables = "treat", at = list(edu_rec_w2 = c("Low", "Middle", "High")))
ame_dd_infl_edu_w2 <- as.data.frame(summary(dd_infl_edu_ma_w2))
ame_dd_infl_edu_w2$edu_rec_w2 <- as.character(ame_dd_infl_edu_w2$edu_rec_w2)
ame_dd_infl_edu_w2$AME <- as.numeric(ame_dd_infl_edu_w2$AME)
ame_dd_infl_edu_w2$SE <- as.numeric(ame_dd_infl_edu_w2$SE)
ame_dd_infl_edu_w2$Treatment <- ame_dd_infl_edu_w2$factor
ame_dd_infl_edu_w2$upper95 <- ame_dd_infl_edu_w2$AME + (ame_dd_infl_edu_w2$SE*1.96)
ame_dd_infl_edu_w2$lower95 <- ame_dd_infl_edu_w2$AME - (ame_dd_infl_edu_w2$SE*1.96)

ame_dd_infl_edu_w2$Treatment[ame_dd_infl_edu_w2$Treatment=="treat2"] <- "Sustainable"
ame_dd_infl_edu_w2$Treatment[ame_dd_infl_edu_w2$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_infl_edu_w2 <- ggplot(ame_dd_infl_edu_w2, aes(colour = edu_rec_w2)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = edu_rec_w2), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("") + 
  scale_fill_grey("") + 
  scale_shape_discrete("") +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. Inflation") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on decreasing debt share
debt_w1$alloc_debt_w1_rec <- debt_w1$alloc_debt_w1*100
debt_w1$dd_decrease_w1 <- ifelse(debt_w1$alloc_debt_w1_rec>=20, 0, ifelse(debt_w1$alloc_debt_w1_rec<20, 1, NA))

dd_decrease_edu_w1 <- lm(dd_decrease_w1 ~ treat*edu_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_decrease_edu_ma_w1 <- margins::margins(dd_decrease_edu_w1, variables = "treat", at = list(edu_rec_w1 = c("Low", "Middle", "High")))
ame_dd_decrease_edu_w1 <- as.data.frame(summary(dd_decrease_edu_ma_w1))
ame_dd_decrease_edu_w1$edu_rec_w1 <- as.character(ame_dd_decrease_edu_w1$edu_rec_w1)
#ame_dd_decrease_edu_w1 <- rbind(ame_dd_decrease_edu_w1, ate_row_tr2, ate_row_tr3)
ame_dd_decrease_edu_w1$AME <- as.numeric(ame_dd_decrease_edu_w1$AME)
ame_dd_decrease_edu_w1$SE <- as.numeric(ame_dd_decrease_edu_w1$SE)
ame_dd_decrease_edu_w1$Treatment <- ame_dd_decrease_edu_w1$factor
ame_dd_decrease_edu_w1$upper95 <- ame_dd_decrease_edu_w1$AME + (ame_dd_decrease_edu_w1$SE*1.96)
ame_dd_decrease_edu_w1$lower95 <- ame_dd_decrease_edu_w1$AME - (ame_dd_decrease_edu_w1$SE*1.96)

ame_dd_decrease_edu_w1$Treatment[ame_dd_decrease_edu_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_decrease_edu_w1$Treatment[ame_dd_decrease_edu_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_decrease_edu_w1 <- ggplot(ame_dd_decrease_edu_w1, aes(colour = edu_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = edu_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Education", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Lower Debt (NHS Funding)") + 
      theme(plot.title = element_text(face = "bold"))

# combine the graphs
ate_hte_graph_w1 <- ggarrange(gg_ame_dd_debt_edu_w1,
                              gg_ame_dd_index_edu_w1 + 
                             theme(axis.text.y = element_blank(),
                                   axis.title.y = element_blank()),
                              gg_ame_dd_cc_edu_w1,  
                              gg_ame_dd_immi_edu_w1 + 
                             theme(axis.text.y = element_blank(),
                                   axis.title.y = element_blank()),
                              gg_ame_dd_nhs_edu_w1,
                              gg_ame_dd_infl_edu_w2 + 
                             theme(axis.text.y = element_blank(),
                                   axis.title.y = element_blank()),
                              nrow=3, ncol=2, common.legend = T,  legend="bottom",
                             widths = c(1, 0.75))
ate_hte_graph_w1

ggsave(ate_hte_graph_w1, width = 18, height = 20, units = c("cm"), file ="appendix/FigureF3.pdf")
```

## Figure F.4: Education (expectations)

```{r, results = 'asis', message=F, echo=FALSE}
# analyze effect of treatment on nhs quality
dd_nhs_qual_edu_w1 <- lm(exp_nhs_qual_w1_z ~ treat*edu_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_nhs_qual_edu_ma_w1 <- margins::margins(dd_nhs_qual_edu_w1, variables = "treat", at = list(edu_rec_w1 = c("Low", "Middle", "High")))
ame_dd_nhs_qual_edu_w1 <- as.data.frame(summary(dd_nhs_qual_edu_ma_w1))
ame_dd_nhs_qual_edu_w1$edu_rec_w1 <- as.character(ame_dd_nhs_qual_edu_w1$edu_rec_w1)
ame_dd_nhs_qual_edu_w1$AME <- as.numeric(ame_dd_nhs_qual_edu_w1$AME)
ame_dd_nhs_qual_edu_w1$SE <- as.numeric(ame_dd_nhs_qual_edu_w1$SE)
ame_dd_nhs_qual_edu_w1$Treatment <- ame_dd_nhs_qual_edu_w1$factor
ame_dd_nhs_qual_edu_w1$upper95 <- ame_dd_nhs_qual_edu_w1$AME + (ame_dd_nhs_qual_edu_w1$SE*1.96)
ame_dd_nhs_qual_edu_w1$lower95 <- ame_dd_nhs_qual_edu_w1$AME - (ame_dd_nhs_qual_edu_w1$SE*1.96)

ame_dd_nhs_qual_edu_w1$Treatment[ame_dd_nhs_qual_edu_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_nhs_qual_edu_w1$Treatment[ame_dd_nhs_qual_edu_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_nhs_qual_edu_w1$edu_rec_w1 <- factor(ame_dd_nhs_qual_edu_w1$edu_rec_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_nhs_qual_edu_w1 <- ggplot(ame_dd_nhs_qual_edu_w1, aes(colour = edu_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = edu_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Education", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("NHS (Quality)") + 
      theme(plot.title = element_text(face = "bold"))


# analyze effect of treatment on nhs costs
dd_nhs_costs_edu_w1 <- lm(exp_nhs_costs_w1_z ~ treat*edu_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_nhs_costs_edu_ma_w1 <- margins::margins(dd_nhs_costs_edu_w1, variables = "treat", at = list(edu_rec_w1 = c("Low", "Middle", "High")))
ame_dd_nhs_costs_edu_w1 <- as.data.frame(summary(dd_nhs_costs_edu_ma_w1))
ame_dd_nhs_costs_edu_w1$edu_rec_w1 <- as.character(ame_dd_nhs_costs_edu_w1$edu_rec_w1)
ame_dd_nhs_costs_edu_w1$AME <- as.numeric(ame_dd_nhs_costs_edu_w1$AME)
ame_dd_nhs_costs_edu_w1$SE <- as.numeric(ame_dd_nhs_costs_edu_w1$SE)
ame_dd_nhs_costs_edu_w1$Treatment <- ame_dd_nhs_costs_edu_w1$factor
ame_dd_nhs_costs_edu_w1$upper95 <- ame_dd_nhs_costs_edu_w1$AME + (ame_dd_nhs_costs_edu_w1$SE*1.96)
ame_dd_nhs_costs_edu_w1$lower95 <- ame_dd_nhs_costs_edu_w1$AME - (ame_dd_nhs_costs_edu_w1$SE*1.96)

ame_dd_nhs_costs_edu_w1$Treatment[ame_dd_nhs_costs_edu_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_nhs_costs_edu_w1$Treatment[ame_dd_nhs_costs_edu_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_nhs_costs_edu_w1$edu_rec_w1 <- factor(ame_dd_nhs_costs_edu_w1$edu_rec_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_nhs_costs_edu_w1 <- ggplot(ame_dd_nhs_costs_edu_w1, aes(colour = edu_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = edu_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Education", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("NHS (Costs)") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on GDP expectation
dd_gdp_edu_w1 <- lm(exp_gdp_w1_z ~ treat*edu_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_gdp_edu_ma_w1 <- margins::margins(dd_gdp_edu_w1, variables = "treat", at = list(edu_rec_w1 = c("Low", "Middle", "High")))
ame_dd_gdp_edu_w1 <- as.data.frame(summary(dd_gdp_edu_ma_w1))
ame_dd_gdp_edu_w1$edu_rec_w1 <- as.character(ame_dd_gdp_edu_w1$edu_rec_w1)
ame_dd_gdp_edu_w1$AME <- as.numeric(ame_dd_gdp_edu_w1$AME)
ame_dd_gdp_edu_w1$SE <- as.numeric(ame_dd_gdp_edu_w1$SE)
ame_dd_gdp_edu_w1$Treatment <- ame_dd_gdp_edu_w1$factor
ame_dd_gdp_edu_w1$upper95 <- ame_dd_gdp_edu_w1$AME + (ame_dd_gdp_edu_w1$SE*1.96)
ame_dd_gdp_edu_w1$lower95 <- ame_dd_gdp_edu_w1$AME - (ame_dd_gdp_edu_w1$SE*1.96)

ame_dd_gdp_edu_w1$Treatment[ame_dd_gdp_edu_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_gdp_edu_w1$Treatment[ame_dd_gdp_edu_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_gdp_edu_w1$edu_rec_w1 <- factor(ame_dd_gdp_edu_w1$edu_rec_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_gdp_edu_w1 <- ggplot(ame_dd_gdp_edu_w1, aes(colour = edu_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = edu_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Education", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +       xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("GDP") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on inflation expectation
dd_infl_edu_w1 <- lm(exp_infl_w1_z ~ treat*edu_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_infl_edu_ma_w1 <- margins::margins(dd_infl_edu_w1, variables = "treat", at = list(edu_rec_w1 = c("Low", "Middle", "High")))
ame_dd_infl_edu_w1 <- as.data.frame(summary(dd_infl_edu_ma_w1))
ame_dd_infl_edu_w1$edu_rec_w1 <- as.character(ame_dd_infl_edu_w1$edu_rec_w1)
ame_dd_infl_edu_w1$AME <- as.numeric(ame_dd_infl_edu_w1$AME)
ame_dd_infl_edu_w1$SE <- as.numeric(ame_dd_infl_edu_w1$SE)
ame_dd_infl_edu_w1$Treatment <- ame_dd_infl_edu_w1$factor
ame_dd_infl_edu_w1$upper95 <- ame_dd_infl_edu_w1$AME + (ame_dd_infl_edu_w1$SE*1.96)
ame_dd_infl_edu_w1$lower95 <- ame_dd_infl_edu_w1$AME - (ame_dd_infl_edu_w1$SE*1.96)

ame_dd_infl_edu_w1$Treatment[ame_dd_infl_edu_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_infl_edu_w1$Treatment[ame_dd_infl_edu_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_infl_edu_w1$edu_rec_w1 <- factor(ame_dd_infl_edu_w1$edu_rec_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_infl_edu_w1 <- ggplot(ame_dd_infl_edu_w1, aes(colour = edu_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = edu_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Education", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +       xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Inflation") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on taxes
dd_tax_edu_w1 <- lm(exp_tax_w1_z ~ treat*edu_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_tax_edu_ma_w1 <- margins::margins(dd_tax_edu_w1, variables = "treat", at = list(edu_rec_w1 = c("Low", "Middle", "High")))
ame_dd_tax_edu_w1 <- as.data.frame(summary(dd_tax_edu_ma_w1))
ame_dd_tax_edu_w1$edu_rec_w1 <- as.character(ame_dd_tax_edu_w1$edu_rec_w1)
ame_dd_tax_edu_w1$AME <- as.numeric(ame_dd_tax_edu_w1$AME)
ame_dd_tax_edu_w1$SE <- as.numeric(ame_dd_tax_edu_w1$SE)
ame_dd_tax_edu_w1$Treatment <- ame_dd_tax_edu_w1$factor
ame_dd_tax_edu_w1$upper95 <- ame_dd_tax_edu_w1$AME + (ame_dd_tax_edu_w1$SE*1.96)
ame_dd_tax_edu_w1$lower95 <- ame_dd_tax_edu_w1$AME - (ame_dd_tax_edu_w1$SE*1.96)

ame_dd_tax_edu_w1$Treatment[ame_dd_tax_edu_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_tax_edu_w1$Treatment[ame_dd_tax_edu_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_tax_edu_w1$edu_rec_w1 <- factor(ame_dd_tax_edu_w1$edu_rec_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_tax_edu_w1 <- ggplot(ame_dd_tax_edu_w1, aes(colour = edu_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = edu_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Education", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +       xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Taxes") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on pension
dd_pen_edu_w1 <- lm(exp_pen_w1_z ~ treat*edu_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_pen_edu_ma_w1 <- margins::margins(dd_pen_edu_w1, variables = "treat", at = list(edu_rec_w1 = c("Low", "Middle", "High")))
ame_dd_pen_edu_w1 <- as.data.frame(summary(dd_pen_edu_ma_w1))
ame_dd_pen_edu_w1$edu_rec_w1 <- as.character(ame_dd_pen_edu_w1$edu_rec_w1)
ame_dd_pen_edu_w1$AME <- as.numeric(ame_dd_pen_edu_w1$AME)
ame_dd_pen_edu_w1$SE <- as.numeric(ame_dd_pen_edu_w1$SE)
ame_dd_pen_edu_w1$Treatment <- ame_dd_pen_edu_w1$factor
ame_dd_pen_edu_w1$upper95 <- ame_dd_pen_edu_w1$AME + (ame_dd_pen_edu_w1$SE*1.96)
ame_dd_pen_edu_w1$lower95 <- ame_dd_pen_edu_w1$AME - (ame_dd_pen_edu_w1$SE*1.96)

ame_dd_pen_edu_w1$Treatment[ame_dd_pen_edu_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_pen_edu_w1$Treatment[ame_dd_pen_edu_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_pen_edu_w1$edu_rec_w1 <- factor(ame_dd_pen_edu_w1$edu_rec_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_pen_edu_w1 <- ggplot(ame_dd_pen_edu_w1, aes(colour = edu_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = edu_rec_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Education", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Education", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
  scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Pensions") + 
      theme(plot.title = element_text(face = "bold"))

exp_hte_graph_edu_w1 <- ggarrange(gg_ame_dd_tax_edu_w1, 
                                  gg_ame_dd_pen_edu_w1 + 
                                          theme(axis.text.y = element_blank(),
                                                axis.title.y = element_blank()), 
                                  gg_ame_dd_nhs_qual_edu_w1, 
                                  gg_ame_dd_nhs_costs_edu_w1 + 
                                          theme(axis.text.y = element_blank(),
                                                axis.title.y = element_blank()), 
                                  gg_ame_dd_gdp_edu_w1, 
                                  gg_ame_dd_infl_edu_w1 + 
                                          theme(axis.text.y = element_blank(),
                                                axis.title.y = element_blank()), 
                                  nrow=3, ncol=2, common.legend = T,  legend="bottom", widths = c(1, 0.75))
exp_hte_graph_edu_w1

ggsave(exp_hte_graph_edu_w1, width = 18, height = 20, units = c("cm"), file ="appendix/FigureF4.pdf")
```

## Figure F.5: Income  

```{r, results = 'asis', message=F, echo=FALSE}
# concern
dd_debt_inc_w1 <- lm(debt_post_z_w1 ~ treat*income_cat_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_debt_inc_ma_w1 <- margins::margins(dd_debt_inc_w1, variables = "treat", at = list(income_cat_w1 = c("Low", "Middle", "High")))
ame_dd_debt_inc_w1 <- as.data.frame(summary(dd_debt_inc_ma_w1))
ame_dd_debt_inc_w1$income_cat_w1 <- as.character(ame_dd_debt_inc_w1$income_cat_w1)
ame_dd_debt_inc_w1$AME <- as.numeric(ame_dd_debt_inc_w1$AME)
ame_dd_debt_inc_w1$SE <- as.numeric(ame_dd_debt_inc_w1$SE)
ame_dd_debt_inc_w1$Treatment <- ame_dd_debt_inc_w1$factor
ame_dd_debt_inc_w1$upper95 <- ame_dd_debt_inc_w1$AME + (ame_dd_debt_inc_w1$SE*1.96)
ame_dd_debt_inc_w1$lower95 <- ame_dd_debt_inc_w1$AME - (ame_dd_debt_inc_w1$SE*1.96)

ame_dd_debt_inc_w1$Treatment[ame_dd_debt_inc_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_debt_inc_w1$Treatment[ame_dd_debt_inc_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_debt_inc_w1$income_cat_w1 <- factor(ame_dd_debt_inc_w1$income_cat_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_debt_inc_w1 <- ggplot(ame_dd_debt_inc_w1, aes(colour = income_cat_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = income_cat_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Income", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
  xlim(-1, 1) +
  xlab("Average treatment effect") +
  theme(legend.position="bottom") +
  theme(legend.position="bottom") + ggtitle("Concern") + 
  theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt index
dd_index_inc_w1 <- lm(debt_index_z_w1 ~ treat*income_cat_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_index_inc_ma_w1 <- margins::margins(dd_index_inc_w1, variables = "treat", at = list(income_cat_w1 = c("Low", "Middle", "High")))
ame_dd_index_inc_w1 <- as.data.frame(summary(dd_index_inc_ma_w1))
ame_dd_index_inc_w1$income_cat_w1 <- as.character(ame_dd_index_inc_w1$income_cat_w1)
ame_dd_index_inc_w1$AME <- as.numeric(ame_dd_index_inc_w1$AME)
ame_dd_index_inc_w1$SE <- as.numeric(ame_dd_index_inc_w1$SE)
ame_dd_index_inc_w1$Treatment <- ame_dd_index_inc_w1$factor
ame_dd_index_inc_w1$upper95 <- ame_dd_index_inc_w1$AME + (ame_dd_index_inc_w1$SE*1.96)
ame_dd_index_inc_w1$lower95 <- ame_dd_index_inc_w1$AME - (ame_dd_index_inc_w1$SE*1.96)

ame_dd_index_inc_w1$Treatment[ame_dd_index_inc_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_index_inc_w1$Treatment[ame_dd_index_inc_w1$Treatment=="treat3"] <- "Unsustainable"

ame_dd_index_inc_w1$income_cat_w1 <- factor(ame_dd_index_inc_w1$income_cat_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_index_inc_w1 <- ggplot(ame_dd_index_inc_w1, aes(colour = income_cat_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = income_cat_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Income", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-1, 1) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt Aversion Index") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. NHS
dd_nhs_inc_w1 <- lm(debt_nhs_rec_w1 ~ treat*income_cat_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_nhs_inc_ma_w1 <- margins::margins(dd_nhs_inc_w1, variables = "treat", at = list(income_cat_w1 = c("Low", "Middle", "High")))
ame_dd_nhs_inc_w1 <- as.data.frame(summary(dd_nhs_inc_ma_w1))
ame_dd_nhs_inc_w1$income_cat_w1 <- as.character(ame_dd_nhs_inc_w1$income_cat_w1)
ame_dd_nhs_inc_w1$AME <- as.numeric(ame_dd_nhs_inc_w1$AME)
ame_dd_nhs_inc_w1$SE <- as.numeric(ame_dd_nhs_inc_w1$SE)
ame_dd_nhs_inc_w1$Treatment <- ame_dd_nhs_inc_w1$factor
ame_dd_nhs_inc_w1$upper95 <- ame_dd_nhs_inc_w1$AME + (ame_dd_nhs_inc_w1$SE*1.96)
ame_dd_nhs_inc_w1$lower95 <- ame_dd_nhs_inc_w1$AME - (ame_dd_nhs_inc_w1$SE*1.96)

ame_dd_nhs_inc_w1$Treatment[ame_dd_nhs_inc_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_nhs_inc_w1$Treatment[ame_dd_nhs_inc_w1$Treatment=="treat3"] <- "Unsustainable"

ame_dd_nhs_inc_w1$income_cat_w1 <- factor(ame_dd_nhs_inc_w1$income_cat_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_nhs_inc_w1 <- ggplot(ame_dd_nhs_inc_w1, aes(colour = income_cat_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = income_cat_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Income", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. NHS") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. climate change
dd_cc_inc_w1 <- lm(debt_CC_rec_w1 ~ treat*income_cat_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_cc_inc_ma_w1 <- margins::margins(dd_cc_inc_w1, variables = "treat", at = list(income_cat_w1 = c("Low", "Middle", "High")))
ame_dd_cc_inc_w1 <- as.data.frame(summary(dd_cc_inc_ma_w1))
ame_dd_cc_inc_w1$income_cat_w1 <- as.character(ame_dd_cc_inc_w1$income_cat_w1)
ame_dd_cc_inc_w1$AME <- as.numeric(ame_dd_cc_inc_w1$AME)
ame_dd_cc_inc_w1$SE <- as.numeric(ame_dd_cc_inc_w1$SE)
ame_dd_cc_inc_w1$Treatment <- ame_dd_cc_inc_w1$factor
ame_dd_cc_inc_w1$upper95 <- ame_dd_cc_inc_w1$AME + (ame_dd_cc_inc_w1$SE*1.96)
ame_dd_cc_inc_w1$lower95 <- ame_dd_cc_inc_w1$AME - (ame_dd_cc_inc_w1$SE*1.96)

ame_dd_cc_inc_w1$Treatment[ame_dd_cc_inc_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_cc_inc_w1$Treatment[ame_dd_cc_inc_w1$Treatment=="treat3"] <- "Unsustainable"

ame_dd_cc_inc_w1$income_cat_w1 <- factor(ame_dd_cc_inc_w1$income_cat_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_cc_inc_w1 <- ggplot(ame_dd_cc_inc_w1, aes(colour = income_cat_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = income_cat_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Income", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. Climate Change") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. immigration
dd_immi_inc_w1 <- lm(debt_immi_rec_w1 ~ treat*income_cat_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_immi_inc_ma_w1 <- margins::margins(dd_immi_inc_w1, variables = "treat", at = list(income_cat_w1 = c("Low", "Middle", "High")))
ame_dd_immi_inc_w1 <- as.data.frame(summary(dd_immi_inc_ma_w1))
ame_dd_immi_inc_w1$income_cat_w1 <- as.character(ame_dd_immi_inc_w1$income_cat_w1)
ame_dd_immi_inc_w1$AME <- as.numeric(ame_dd_immi_inc_w1$AME)
ame_dd_immi_inc_w1$SE <- as.numeric(ame_dd_immi_inc_w1$SE)
ame_dd_immi_inc_w1$Treatment <- ame_dd_immi_inc_w1$factor
ame_dd_immi_inc_w1$upper95 <- ame_dd_immi_inc_w1$AME + (ame_dd_immi_inc_w1$SE*1.96)
ame_dd_immi_inc_w1$lower95 <- ame_dd_immi_inc_w1$AME - (ame_dd_immi_inc_w1$SE*1.96)

ame_dd_immi_inc_w1$Treatment[ame_dd_immi_inc_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_immi_inc_w1$Treatment[ame_dd_immi_inc_w1$Treatment=="treat3"] <- "Unsustainable"

ame_dd_immi_inc_w1$income_cat_w1 <- factor(ame_dd_immi_inc_w1$income_cat_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_immi_inc_w1 <- ggplot(ame_dd_immi_inc_w1, aes(colour = income_cat_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = income_cat_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Income", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. Immigration") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. inflation
dd_infl_inc_w2 <- lm(debt_infl_rec_w2 ~ treat*income_cat_w2 + as.factor(debt_pre_w2), data = debt_w2)
dd_infl_inc_ma_w2 <- margins::margins(dd_infl_inc_w2, variables = "treat", at = list(income_cat_w2 = c("Low", "Middle", "High")))
ame_dd_infl_inc_w2 <- as.data.frame(summary(dd_infl_inc_ma_w2))
ame_dd_infl_inc_w2$income_cat_w2 <- as.character(ame_dd_infl_inc_w2$income_cat_w2)
ame_dd_infl_inc_w2$AME <- as.numeric(ame_dd_infl_inc_w2$AME)
ame_dd_infl_inc_w2$SE <- as.numeric(ame_dd_infl_inc_w2$SE)
ame_dd_infl_inc_w2$Treatment <- ame_dd_infl_inc_w2$factor
ame_dd_infl_inc_w2$upper95 <- ame_dd_infl_inc_w2$AME + (ame_dd_infl_inc_w2$SE*1.96)
ame_dd_infl_inc_w2$lower95 <- ame_dd_infl_inc_w2$AME - (ame_dd_infl_inc_w2$SE*1.96)

ame_dd_infl_inc_w2$Treatment[ame_dd_infl_inc_w2$Treatment=="treat2"] <- "Sustainable"
ame_dd_infl_inc_w2$Treatment[ame_dd_infl_inc_w2$Treatment=="treat3"] <- "Unsustainable"

ame_dd_infl_inc_w2$income_cat_w1 <- factor(ame_dd_infl_inc_w2$income_cat_w2, levels = c("Low", "Middle", "High"))

gg_ame_dd_infl_inc_w2 <- ggplot(ame_dd_infl_inc_w2, aes(colour = income_cat_w2)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = income_cat_w2), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("") + 
  scale_fill_grey("") + 
  scale_shape_discrete("") +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. Inflation") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on decreasing debt share
debt_w1$alloc_debt_w1_rec <- debt_w1$alloc_debt_w1*100
debt_w1$dd_decrease_w1 <- ifelse(debt_w1$alloc_debt_w1_rec>=20, 0, ifelse(debt_w1$alloc_debt_w1_rec<20, 1, NA))

dd_decrease_inc_w1 <- lm(dd_decrease_w1 ~ treat*income_cat_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_decrease_inc_ma_w1 <- margins::margins(dd_decrease_inc_w1, variables = "treat", at = list(income_cat_w1 = c("Low", "Middle", "High")))
ame_dd_decrease_inc_w1 <- as.data.frame(summary(dd_decrease_inc_ma_w1))
ame_dd_decrease_inc_w1$income_cat_w1 <- as.character(ame_dd_decrease_inc_w1$income_cat_w1)
#ame_dd_decrease_inc_w1 <- rbind(ame_dd_decrease_inc_w1, ate_row_tr2, ate_row_tr3)
ame_dd_decrease_inc_w1$AME <- as.numeric(ame_dd_decrease_inc_w1$AME)
ame_dd_decrease_inc_w1$SE <- as.numeric(ame_dd_decrease_inc_w1$SE)
ame_dd_decrease_inc_w1$Treatment <- ame_dd_decrease_inc_w1$factor
ame_dd_decrease_inc_w1$upper95 <- ame_dd_decrease_inc_w1$AME + (ame_dd_decrease_inc_w1$SE*1.96)
ame_dd_decrease_inc_w1$lower95 <- ame_dd_decrease_inc_w1$AME - (ame_dd_decrease_inc_w1$SE*1.96)

ame_dd_decrease_inc_w1$Treatment[ame_dd_decrease_inc_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_decrease_inc_w1$Treatment[ame_dd_decrease_inc_w1$Treatment=="treat3"] <- "Unsustainable"

ame_dd_decrease_inc_w1$income_cat_w1 <- factor(ame_dd_decrease_inc_w1$income_cat_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_decrease_inc_w1 <- ggplot(ame_dd_decrease_inc_w1, aes(colour = income_cat_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = income_cat_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Income", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Lower Debt (NHS Funding)") + 
      theme(plot.title = element_text(face = "bold"))

# combine the graphs
ate_hte_graph_w1 <- ggarrange(gg_ame_dd_debt_inc_w1, 
                              gg_ame_dd_index_inc_w1 + 
                                theme(axis.text.y = element_blank(),
                                      axis.title.y = element_blank()), 
                              gg_ame_dd_cc_inc_w1, 
                              gg_ame_dd_immi_inc_w1 + 
                                theme(axis.text.y = element_blank(),
                                      axis.title.y = element_blank()), 
                              gg_ame_dd_nhs_inc_w1,
                              gg_ame_dd_infl_inc_w2 + 
                                theme(axis.text.y = element_blank(),
                                      axis.title.y = element_blank()),
                              nrow=3, ncol=2, common.legend = T,  legend="bottom",
                             widths = c(1, 0.75))
ate_hte_graph_w1

ggsave(ate_hte_graph_w1, width = 18, height = 20, units = c("cm"), file ="appendix/FigureF5.pdf")
```

## Figure F.6: Income (expectations)

```{r, results = 'asis', message=F, echo=FALSE}
# analyze effect of treatment on nhs qual
dd_nhs_qual_inc_w1 <- lm(exp_nhs_qual_w1_z ~ treat*income_cat_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_nhs_qual_inc_ma_w1 <- margins::margins(dd_nhs_qual_inc_w1, variables = "treat", at = list(income_cat_w1 = c("Low", "Middle", "High")))
ame_dd_nhs_qual_inc_w1 <- as.data.frame(summary(dd_nhs_qual_inc_ma_w1))
ame_dd_nhs_qual_inc_w1$income_cat_w1 <- as.character(ame_dd_nhs_qual_inc_w1$income_cat_w1)
ame_dd_nhs_qual_inc_w1$AME <- as.numeric(ame_dd_nhs_qual_inc_w1$AME)
ame_dd_nhs_qual_inc_w1$SE <- as.numeric(ame_dd_nhs_qual_inc_w1$SE)
ame_dd_nhs_qual_inc_w1$Treatment <- ame_dd_nhs_qual_inc_w1$factor
ame_dd_nhs_qual_inc_w1$upper95 <- ame_dd_nhs_qual_inc_w1$AME + (ame_dd_nhs_qual_inc_w1$SE*1.96)
ame_dd_nhs_qual_inc_w1$lower95 <- ame_dd_nhs_qual_inc_w1$AME - (ame_dd_nhs_qual_inc_w1$SE*1.96)

ame_dd_nhs_qual_inc_w1$Treatment[ame_dd_nhs_qual_inc_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_nhs_qual_inc_w1$Treatment[ame_dd_nhs_qual_inc_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_nhs_qual_inc_w1$income_cat_w1 <- factor(ame_dd_nhs_qual_inc_w1$income_cat_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_nhs_qual_inc_w1 <- ggplot(ame_dd_nhs_qual_inc_w1, aes(colour = income_cat_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = income_cat_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Income", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("NHS (Quality)") + 
      theme(plot.title = element_text(face = "bold"))


# analyze effect of treatment on nhs costs
dd_nhs_costs_inc_w1 <- lm(exp_nhs_costs_w1_z ~ treat*income_cat_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_nhs_costs_inc_ma_w1 <- margins::margins(dd_nhs_costs_inc_w1, variables = "treat", at = list(income_cat_w1 = c("Low", "Middle", "High")))
ame_dd_nhs_costs_inc_w1 <- as.data.frame(summary(dd_nhs_costs_inc_ma_w1))
ame_dd_nhs_costs_inc_w1$income_cat_w1 <- as.character(ame_dd_nhs_costs_inc_w1$income_cat_w1)
ame_dd_nhs_costs_inc_w1$AME <- as.numeric(ame_dd_nhs_costs_inc_w1$AME)
ame_dd_nhs_costs_inc_w1$SE <- as.numeric(ame_dd_nhs_costs_inc_w1$SE)
ame_dd_nhs_costs_inc_w1$Treatment <- ame_dd_nhs_costs_inc_w1$factor
ame_dd_nhs_costs_inc_w1$upper95 <- ame_dd_nhs_costs_inc_w1$AME + (ame_dd_nhs_costs_inc_w1$SE*1.96)
ame_dd_nhs_costs_inc_w1$lower95 <- ame_dd_nhs_costs_inc_w1$AME - (ame_dd_nhs_costs_inc_w1$SE*1.96)

ame_dd_nhs_costs_inc_w1$Treatment[ame_dd_nhs_costs_inc_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_nhs_costs_inc_w1$Treatment[ame_dd_nhs_costs_inc_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_nhs_costs_inc_w1$income_cat_w1 <- factor(ame_dd_nhs_costs_inc_w1$income_cat_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_nhs_costs_inc_w1 <- ggplot(ame_dd_nhs_costs_inc_w1, aes(colour = income_cat_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = income_cat_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Income", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("NHS (Costs)") + 
      theme(plot.title = element_text(face = "bold"))


# analyze effect of treatment on GDP expectation
dd_gdp_inc_w1 <- lm(exp_gdp_w1_z ~ treat*income_cat_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_gdp_inc_ma_w1 <- margins::margins(dd_gdp_inc_w1, variables = "treat", at = list(income_cat_w1 = c("Low", "Middle", "High")))
ame_dd_gdp_inc_w1 <- as.data.frame(summary(dd_gdp_inc_ma_w1))
ame_dd_gdp_inc_w1$income_cat_w1 <- as.character(ame_dd_gdp_inc_w1$income_cat_w1)
ame_dd_gdp_inc_w1$AME <- as.numeric(ame_dd_gdp_inc_w1$AME)
ame_dd_gdp_inc_w1$SE <- as.numeric(ame_dd_gdp_inc_w1$SE)
ame_dd_gdp_inc_w1$Treatment <- ame_dd_gdp_inc_w1$factor
ame_dd_gdp_inc_w1$upper95 <- ame_dd_gdp_inc_w1$AME + (ame_dd_gdp_inc_w1$SE*1.96)
ame_dd_gdp_inc_w1$lower95 <- ame_dd_gdp_inc_w1$AME - (ame_dd_gdp_inc_w1$SE*1.96)

ame_dd_gdp_inc_w1$Treatment[ame_dd_gdp_inc_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_gdp_inc_w1$Treatment[ame_dd_gdp_inc_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_gdp_inc_w1$income_cat_w1 <- factor(ame_dd_gdp_inc_w1$income_cat_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_gdp_inc_w1 <- ggplot(ame_dd_gdp_inc_w1, aes(colour = income_cat_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = income_cat_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Income", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +       xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("GDP") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on inflation expectation
dd_infl_inc_w1 <- lm(exp_infl_w1_z ~ treat*income_cat_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_infl_inc_ma_w1 <- margins::margins(dd_infl_inc_w1, variables = "treat", at = list(income_cat_w1 = c("Low", "Middle", "High")))
ame_dd_infl_inc_w1 <- as.data.frame(summary(dd_infl_inc_ma_w1))
ame_dd_infl_inc_w1$income_cat_w1 <- as.character(ame_dd_infl_inc_w1$income_cat_w1)
ame_dd_infl_inc_w1$AME <- as.numeric(ame_dd_infl_inc_w1$AME)
ame_dd_infl_inc_w1$SE <- as.numeric(ame_dd_infl_inc_w1$SE)
ame_dd_infl_inc_w1$Treatment <- ame_dd_infl_inc_w1$factor
ame_dd_infl_inc_w1$upper95 <- ame_dd_infl_inc_w1$AME + (ame_dd_infl_inc_w1$SE*1.96)
ame_dd_infl_inc_w1$lower95 <- ame_dd_infl_inc_w1$AME - (ame_dd_infl_inc_w1$SE*1.96)

ame_dd_infl_inc_w1$Treatment[ame_dd_infl_inc_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_infl_inc_w1$Treatment[ame_dd_infl_inc_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_infl_inc_w1$income_cat_w1 <- factor(ame_dd_infl_inc_w1$income_cat_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_infl_inc_w1 <- ggplot(ame_dd_infl_inc_w1, aes(colour = income_cat_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = income_cat_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Income", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +       xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Inflation") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on taxes
dd_tax_inc_w1 <- lm(exp_tax_w1_z ~ treat*income_cat_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_tax_inc_ma_w1 <- margins::margins(dd_tax_inc_w1, variables = "treat", at = list(income_cat_w1 = c("Low", "Middle", "High")))
ame_dd_tax_inc_w1 <- as.data.frame(summary(dd_tax_inc_ma_w1))
ame_dd_tax_inc_w1$income_cat_w1 <- as.character(ame_dd_tax_inc_w1$income_cat_w1)
ame_dd_tax_inc_w1$AME <- as.numeric(ame_dd_tax_inc_w1$AME)
ame_dd_tax_inc_w1$SE <- as.numeric(ame_dd_tax_inc_w1$SE)
ame_dd_tax_inc_w1$Treatment <- ame_dd_tax_inc_w1$factor
ame_dd_tax_inc_w1$upper95 <- ame_dd_tax_inc_w1$AME + (ame_dd_tax_inc_w1$SE*1.96)
ame_dd_tax_inc_w1$lower95 <- ame_dd_tax_inc_w1$AME - (ame_dd_tax_inc_w1$SE*1.96)

ame_dd_tax_inc_w1$Treatment[ame_dd_tax_inc_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_tax_inc_w1$Treatment[ame_dd_tax_inc_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_tax_inc_w1$income_cat_w1 <- factor(ame_dd_tax_inc_w1$income_cat_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_tax_inc_w1 <- ggplot(ame_dd_tax_inc_w1, aes(colour = income_cat_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = income_cat_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Income", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +       xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Taxes") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on pension
dd_pen_inc_w1 <- lm(exp_pen_w1_z ~ treat*income_cat_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_pen_inc_ma_w1 <- margins::margins(dd_pen_inc_w1, variables = "treat", at = list(income_cat_w1 = c("Low", "Middle", "High")))
ame_dd_pen_inc_w1 <- as.data.frame(summary(dd_pen_inc_ma_w1))
ame_dd_pen_inc_w1$income_cat_w1 <- as.character(ame_dd_pen_inc_w1$income_cat_w1)
ame_dd_pen_inc_w1$AME <- as.numeric(ame_dd_pen_inc_w1$AME)
ame_dd_pen_inc_w1$SE <- as.numeric(ame_dd_pen_inc_w1$SE)
ame_dd_pen_inc_w1$Treatment <- ame_dd_pen_inc_w1$factor
ame_dd_pen_inc_w1$upper95 <- ame_dd_pen_inc_w1$AME + (ame_dd_pen_inc_w1$SE*1.96)
ame_dd_pen_inc_w1$lower95 <- ame_dd_pen_inc_w1$AME - (ame_dd_pen_inc_w1$SE*1.96)

ame_dd_pen_inc_w1$Treatment[ame_dd_pen_inc_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_pen_inc_w1$Treatment[ame_dd_pen_inc_w1$Treatment=="treat3"] <- "Unsustainable"

# Add factor levels for consistent ordering
ame_dd_pen_inc_w1$income_cat_w1 <- factor(ame_dd_pen_inc_w1$income_cat_w1, levels = c("Low", "Middle", "High"))

gg_ame_dd_pen_inc_w1 <- ggplot(ame_dd_pen_inc_w1, aes(colour = income_cat_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=-0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = income_cat_w1), position = position_dodge(width=-0.5), size=2) +
  theme_bw() + scale_color_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_fill_grey("Income", breaks=c("Low", "Middle", "High")) + 
  scale_shape_discrete("Income", breaks=c("Low", "Middle", "High")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
  scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Pensions") + 
      theme(plot.title = element_text(face = "bold"))

exp_hte_graph_inc_w1 <- ggarrange(gg_ame_dd_tax_inc_w1, 
                                  gg_ame_dd_pen_inc_w1 + 
                                          theme(axis.text.y = element_blank(),
                                                axis.title.y = element_blank()), 
                                  gg_ame_dd_nhs_qual_inc_w1, 
                                  gg_ame_dd_nhs_costs_inc_w1 + 
                                          theme(axis.text.y = element_blank(),
                                                axis.title.y = element_blank()), 
                                  gg_ame_dd_gdp_inc_w1, 
                                  gg_ame_dd_infl_inc_w1 + 
                                          theme(axis.text.y = element_blank(),
                                                axis.title.y = element_blank()), nrow=3, ncol=2, common.legend = T, legend="bottom", widths = c(1, 0.75))
exp_hte_graph_inc_w1

ggsave(exp_hte_graph_inc_w1, width = 18, height = 20, units = c("cm"), file ="appendix/FigureF6.pdf")
```

## Figure F.7: Age

```{r, results = 'asis', message=F, echo=FALSE}
# concern
dd_debt_age_w1 <- lm(debt_post_z_w1 ~ treat*age_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_debt_age_ma_w1 <- margins::margins(dd_debt_age_w1, variables = "treat", at = list(age_rec_w1 = c("Up to 35", "35-50", "51-65", "65+")))
ame_dd_debt_age_w1 <- as.data.frame(summary(dd_debt_age_ma_w1))
ame_dd_debt_age_w1$age_rec_w1 <- as.character(ame_dd_debt_age_w1$age_rec_w1)
ame_dd_debt_age_w1$AME <- as.numeric(ame_dd_debt_age_w1$AME)
ame_dd_debt_age_w1$SE <- as.numeric(ame_dd_debt_age_w1$SE)
ame_dd_debt_age_w1$Treatment <- ame_dd_debt_age_w1$factor
ame_dd_debt_age_w1$upper95 <- ame_dd_debt_age_w1$AME + (ame_dd_debt_age_w1$SE*1.96)
ame_dd_debt_age_w1$lower95 <- ame_dd_debt_age_w1$AME - (ame_dd_debt_age_w1$SE*1.96)

ame_dd_debt_age_w1$Treatment[ame_dd_debt_age_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_debt_age_w1$Treatment[ame_dd_debt_age_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_debt_age_w1 <- ggplot(ame_dd_debt_age_w1, aes(colour = age_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = age_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_fill_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_shape_discrete("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
  xlim(-1,1) +
  xlab("Average treatment effect") +
  theme(legend.position="bottom") +
  theme(legend.position="bottom") + ggtitle("Concern") + 
  theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt index
dd_index_age_w1 <- lm(debt_index_z_w1 ~ treat*age_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_index_age_ma_w1 <- margins::margins(dd_index_age_w1, variables = "treat", at = list(age_rec_w1 = c("Up to 35", "35-50", "51-65", "65+")))
ame_dd_index_age_w1 <- as.data.frame(summary(dd_index_age_ma_w1))
ame_dd_index_age_w1$age_rec_w1 <- as.character(ame_dd_index_age_w1$age_rec_w1)
ame_dd_index_age_w1$AME <- as.numeric(ame_dd_index_age_w1$AME)
ame_dd_index_age_w1$SE <- as.numeric(ame_dd_index_age_w1$SE)
ame_dd_index_age_w1$Treatment <- ame_dd_index_age_w1$factor
ame_dd_index_age_w1$upper95 <- ame_dd_index_age_w1$AME + (ame_dd_index_age_w1$SE*1.96)
ame_dd_index_age_w1$lower95 <- ame_dd_index_age_w1$AME - (ame_dd_index_age_w1$SE*1.96)

ame_dd_index_age_w1$Treatment[ame_dd_index_age_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_index_age_w1$Treatment[ame_dd_index_age_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_index_age_w1 <- ggplot(ame_dd_index_age_w1, aes(colour = age_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = age_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_fill_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_shape_discrete("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-1, 1) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt Aversion Index") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. NHS
dd_nhs_age_w1 <- lm(debt_nhs_rec_w1 ~ treat*age_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_nhs_age_ma_w1 <- margins::margins(dd_nhs_age_w1, variables = "treat", at = list(age_rec_w1 = c("Up to 35", "35-50", "51-65", "65+")))
ame_dd_nhs_age_w1 <- as.data.frame(summary(dd_nhs_age_ma_w1))
ame_dd_nhs_age_w1$age_rec_w1 <- as.character(ame_dd_nhs_age_w1$age_rec_w1)
ame_dd_nhs_age_w1$AME <- as.numeric(ame_dd_nhs_age_w1$AME)
ame_dd_nhs_age_w1$SE <- as.numeric(ame_dd_nhs_age_w1$SE)
ame_dd_nhs_age_w1$Treatment <- ame_dd_nhs_age_w1$factor
ame_dd_nhs_age_w1$upper95 <- ame_dd_nhs_age_w1$AME + (ame_dd_nhs_age_w1$SE*1.96)
ame_dd_nhs_age_w1$lower95 <- ame_dd_nhs_age_w1$AME - (ame_dd_nhs_age_w1$SE*1.96)

ame_dd_nhs_age_w1$Treatment[ame_dd_nhs_age_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_nhs_age_w1$Treatment[ame_dd_nhs_age_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_nhs_age_w1 <- ggplot(ame_dd_nhs_age_w1, aes(colour = age_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = age_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_fill_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_shape_discrete("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. NHS") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. climate change
dd_cc_age_w1 <- lm(debt_CC_rec_w1 ~ treat*age_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_cc_age_ma_w1 <- margins::margins(dd_cc_age_w1, variables = "treat", at = list(age_rec_w1 = c("Up to 35", "35-50", "51-65", "65+")))
ame_dd_cc_age_w1 <- as.data.frame(summary(dd_cc_age_ma_w1))
ame_dd_cc_age_w1$age_rec_w1 <- as.character(ame_dd_cc_age_w1$age_rec_w1)
ame_dd_cc_age_w1$AME <- as.numeric(ame_dd_cc_age_w1$AME)
ame_dd_cc_age_w1$SE <- as.numeric(ame_dd_cc_age_w1$SE)
ame_dd_cc_age_w1$Treatment <- ame_dd_cc_age_w1$factor
ame_dd_cc_age_w1$upper95 <- ame_dd_cc_age_w1$AME + (ame_dd_cc_age_w1$SE*1.96)
ame_dd_cc_age_w1$lower95 <- ame_dd_cc_age_w1$AME - (ame_dd_cc_age_w1$SE*1.96)

ame_dd_cc_age_w1$Treatment[ame_dd_cc_age_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_cc_age_w1$Treatment[ame_dd_cc_age_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_cc_age_w1 <- ggplot(ame_dd_cc_age_w1, aes(colour = age_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = age_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_fill_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_shape_discrete("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. Climate Change") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. immigration
dd_immi_age_w1 <- lm(debt_immi_rec_w1 ~ treat*age_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_immi_age_ma_w1 <- margins::margins(dd_immi_age_w1, variables = "treat", at = list(age_rec_w1 = c("Up to 35", "35-50", "51-65", "65+")))
ame_dd_immi_age_w1 <- as.data.frame(summary(dd_immi_age_ma_w1))
ame_dd_immi_age_w1$age_rec_w1 <- as.character(ame_dd_immi_age_w1$age_rec_w1)
ame_dd_immi_age_w1$AME <- as.numeric(ame_dd_immi_age_w1$AME)
ame_dd_immi_age_w1$SE <- as.numeric(ame_dd_immi_age_w1$SE)
ame_dd_immi_age_w1$Treatment <- ame_dd_immi_age_w1$factor
ame_dd_immi_age_w1$upper95 <- ame_dd_immi_age_w1$AME + (ame_dd_immi_age_w1$SE*1.96)
ame_dd_immi_age_w1$lower95 <- ame_dd_immi_age_w1$AME - (ame_dd_immi_age_w1$SE*1.96)

ame_dd_immi_age_w1$Treatment[ame_dd_immi_age_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_immi_age_w1$Treatment[ame_dd_immi_age_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_immi_age_w1 <- ggplot(ame_dd_immi_age_w1, aes(colour = age_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = age_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_fill_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_shape_discrete("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. Immigration") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on debt vs. inflation
dd_infl_age_w2 <- lm(debt_infl_rec_w2 ~ treat*age_rec_w2 + as.factor(debt_pre_w2), data = debt_w2)
dd_infl_age_ma_w2 <- margins::margins(dd_infl_age_w2, variables = "treat", at = list(age_rec_w2 = c("Up to 35", "35-50", "51-65", "65+")))
ame_dd_infl_age_w2 <- as.data.frame(summary(dd_infl_age_ma_w2))
ame_dd_infl_age_w2$age_rec_w2 <- as.character(ame_dd_infl_age_w2$age_rec_w2)
ame_dd_infl_age_w2$AME <- as.numeric(ame_dd_infl_age_w2$AME)
ame_dd_infl_age_w2$SE <- as.numeric(ame_dd_infl_age_w2$SE)
ame_dd_infl_age_w2$Treatment <- ame_dd_infl_age_w2$factor
ame_dd_infl_age_w2$upper95 <- ame_dd_infl_age_w2$AME + (ame_dd_infl_age_w2$SE*1.96)
ame_dd_infl_age_w2$lower95 <- ame_dd_infl_age_w2$AME - (ame_dd_infl_age_w2$SE*1.96)

ame_dd_infl_age_w2$Treatment[ame_dd_infl_age_w2$Treatment=="treat2"] <- "Sustainable"
ame_dd_infl_age_w2$Treatment[ame_dd_infl_age_w2$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_infl_age_w2 <- ggplot(ame_dd_infl_age_w2, aes(colour = age_rec_w2)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = age_rec_w2), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("") + 
  scale_fill_grey("") + 
  scale_shape_discrete("") +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Debt vs. Inflation") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on decreasing debt share
debt_w1$alloc_debt_w1_rec <- debt_w1$alloc_debt_w1*100
debt_w1$dd_decrease_w1 <- ifelse(debt_w1$alloc_debt_w1_rec>=20, 0, ifelse(debt_w1$alloc_debt_w1_rec<20, 1, NA))

dd_decrease_age_w1 <- lm(dd_decrease_w1 ~ treat*age_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_decrease_age_ma_w1 <- margins::margins(dd_decrease_age_w1, variables = "treat", at = list(age_rec_w1 = c("Up to 35", "35-50", "51-65", "65+")))
ame_dd_decrease_age_w1 <- as.data.frame(summary(dd_decrease_age_ma_w1))
ame_dd_decrease_age_w1$age_rec_w1 <- as.character(ame_dd_decrease_age_w1$age_rec_w1)
#ame_dd_decrease_age_w1 <- rbind(ame_dd_decrease_age_w1, ate_row_tr2, ate_row_tr3)
ame_dd_decrease_age_w1$AME <- as.numeric(ame_dd_decrease_age_w1$AME)
ame_dd_decrease_age_w1$SE <- as.numeric(ame_dd_decrease_age_w1$SE)
ame_dd_decrease_age_w1$Treatment <- ame_dd_decrease_age_w1$factor
ame_dd_decrease_age_w1$upper95 <- ame_dd_decrease_age_w1$AME + (ame_dd_decrease_age_w1$SE*1.96)
ame_dd_decrease_age_w1$lower95 <- ame_dd_decrease_age_w1$AME - (ame_dd_decrease_age_w1$SE*1.96)

ame_dd_decrease_age_w1$Treatment[ame_dd_decrease_age_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_decrease_age_w1$Treatment[ame_dd_decrease_age_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_decrease_age_w1 <- ggplot(ame_dd_decrease_age_w1, aes(colour = age_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = age_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_fill_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_shape_discrete("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.3, 0.3) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Lower Debt (NHS Funding)") + 
      theme(plot.title = element_text(face = "bold"))

# combine the graphs
ate_hte_graph_w1 <- ggarrange(gg_ame_dd_debt_age_w1, 
                              gg_ame_dd_index_age_w1 + 
                             theme(axis.text.y = element_blank(),
                                   axis.title.y = element_blank()), 
                              gg_ame_dd_cc_age_w1, 
                              gg_ame_dd_immi_age_w1 + 
                             theme(axis.text.y = element_blank(),
                                   axis.title.y = element_blank()), 
                              gg_ame_dd_nhs_age_w1, 
                              gg_ame_dd_infl_age_w2 + 
                             theme(axis.text.y = element_blank(),
                                   axis.title.y = element_blank()),
                            nrow=3, ncol=2, common.legend = T, legend="bottom", widths = c(1, 0.75))
ate_hte_graph_w1

ggsave(ate_hte_graph_w1, width = 18, height = 20, units = c("cm"), file ="appendix/FigureF7.pdf")
```

## Figure F.8: Age (expectations)

```{r, results = 'asis', message=F, echo=FALSE}
# analyze effect of treatment on nhs quality
dd_nhs_qual_age_w1 <- lm(exp_nhs_qual_w1_z ~ treat*age_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_nhs_qual_age_ma_w1 <- margins::margins(dd_nhs_qual_age_w1, variables = "treat", at = list(age_rec_w1 = c("Up to 35", "35-50", "51-65", "65+")))
ame_dd_nhs_qual_age_w1 <- as.data.frame(summary(dd_nhs_qual_age_ma_w1))
ame_dd_nhs_qual_age_w1$age_rec_w1 <- as.character(ame_dd_nhs_qual_age_w1$age_rec_w1)
ame_dd_nhs_qual_age_w1$AME <- as.numeric(ame_dd_nhs_qual_age_w1$AME)
ame_dd_nhs_qual_age_w1$SE <- as.numeric(ame_dd_nhs_qual_age_w1$SE)
ame_dd_nhs_qual_age_w1$Treatment <- ame_dd_nhs_qual_age_w1$factor
ame_dd_nhs_qual_age_w1$upper95 <- ame_dd_nhs_qual_age_w1$AME + (ame_dd_nhs_qual_age_w1$SE*1.96)
ame_dd_nhs_qual_age_w1$lower95 <- ame_dd_nhs_qual_age_w1$AME - (ame_dd_nhs_qual_age_w1$SE*1.96)

ame_dd_nhs_qual_age_w1$Treatment[ame_dd_nhs_qual_age_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_nhs_qual_age_w1$Treatment[ame_dd_nhs_qual_age_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_nhs_qual_age_w1 <- ggplot(ame_dd_nhs_qual_age_w1, aes(colour = age_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = age_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_fill_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_shape_discrete("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("NHS (Quality)") + 
      theme(plot.title = element_text(face = "bold"))


# analyze effect of treatment on nhs costs
dd_nhs_costs_age_w1 <- lm(exp_nhs_costs_w1_z ~ treat*age_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_nhs_costs_age_ma_w1 <- margins::margins(dd_nhs_costs_age_w1, variables = "treat", at = list(age_rec_w1 = c("Up to 35", "35-50", "51-65", "65+")))
ame_dd_nhs_costs_age_w1 <- as.data.frame(summary(dd_nhs_costs_age_ma_w1))
ame_dd_nhs_costs_age_w1$age_rec_w1 <- as.character(ame_dd_nhs_costs_age_w1$age_rec_w1)
ame_dd_nhs_costs_age_w1$AME <- as.numeric(ame_dd_nhs_costs_age_w1$AME)
ame_dd_nhs_costs_age_w1$SE <- as.numeric(ame_dd_nhs_costs_age_w1$SE)
ame_dd_nhs_costs_age_w1$Treatment <- ame_dd_nhs_costs_age_w1$factor
ame_dd_nhs_costs_age_w1$upper95 <- ame_dd_nhs_costs_age_w1$AME + (ame_dd_nhs_costs_age_w1$SE*1.96)
ame_dd_nhs_costs_age_w1$lower95 <- ame_dd_nhs_costs_age_w1$AME - (ame_dd_nhs_costs_age_w1$SE*1.96)

ame_dd_nhs_costs_age_w1$Treatment[ame_dd_nhs_costs_age_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_nhs_costs_age_w1$Treatment[ame_dd_nhs_costs_age_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_nhs_costs_age_w1 <- ggplot(ame_dd_nhs_costs_age_w1, aes(colour = age_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = age_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_fill_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_shape_discrete("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("NHS (Costs)") + 
      theme(plot.title = element_text(face = "bold"))


# analyze effect of treatment on GDP expectation
dd_gdp_age_w1 <- lm(exp_gdp_w1_z ~ treat*age_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_gdp_age_ma_w1 <- margins::margins(dd_gdp_age_w1, variables = "treat", at = list(age_rec_w1 = c("Up to 35", "35-50", "51-65", "65+")))
ame_dd_gdp_age_w1 <- as.data.frame(summary(dd_gdp_age_ma_w1))
ame_dd_gdp_age_w1$age_rec_w1 <- as.character(ame_dd_gdp_age_w1$age_rec_w1)
ame_dd_gdp_age_w1$AME <- as.numeric(ame_dd_gdp_age_w1$AME)
ame_dd_gdp_age_w1$SE <- as.numeric(ame_dd_gdp_age_w1$SE)
ame_dd_gdp_age_w1$Treatment <- ame_dd_gdp_age_w1$factor
ame_dd_gdp_age_w1$upper95 <- ame_dd_gdp_age_w1$AME + (ame_dd_gdp_age_w1$SE*1.96)
ame_dd_gdp_age_w1$lower95 <- ame_dd_gdp_age_w1$AME - (ame_dd_gdp_age_w1$SE*1.96)

ame_dd_gdp_age_w1$Treatment[ame_dd_gdp_age_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_gdp_age_w1$Treatment[ame_dd_gdp_age_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_gdp_age_w1 <- ggplot(ame_dd_gdp_age_w1, aes(colour = age_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = age_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_fill_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_shape_discrete("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +       xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("GDP") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on inflation expectation
dd_infl_age_w1 <- lm(exp_infl_w1_z ~ treat*age_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_infl_age_ma_w1 <- margins::margins(dd_infl_age_w1, variables = "treat", at = list(age_rec_w1 = c("Up to 35", "35-50", "51-65", "65+")))
ame_dd_infl_age_w1 <- as.data.frame(summary(dd_infl_age_ma_w1))
ame_dd_infl_age_w1$age_rec_w1 <- as.character(ame_dd_infl_age_w1$age_rec_w1)
ame_dd_infl_age_w1$AME <- as.numeric(ame_dd_infl_age_w1$AME)
ame_dd_infl_age_w1$SE <- as.numeric(ame_dd_infl_age_w1$SE)
ame_dd_infl_age_w1$Treatment <- ame_dd_infl_age_w1$factor
ame_dd_infl_age_w1$upper95 <- ame_dd_infl_age_w1$AME + (ame_dd_infl_age_w1$SE*1.96)
ame_dd_infl_age_w1$lower95 <- ame_dd_infl_age_w1$AME - (ame_dd_infl_age_w1$SE*1.96)

ame_dd_infl_age_w1$Treatment[ame_dd_infl_age_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_infl_age_w1$Treatment[ame_dd_infl_age_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_infl_age_w1 <- ggplot(ame_dd_infl_age_w1, aes(colour = age_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = age_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_fill_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_shape_discrete("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +       xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Inflation") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on taxes
dd_tax_age_w1 <- lm(exp_tax_w1_z ~ treat*age_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_tax_age_ma_w1 <- margins::margins(dd_tax_age_w1, variables = "treat", at = list(age_rec_w1 = c("Up to 35", "35-50", "51-65", "65+")))
ame_dd_tax_age_w1 <- as.data.frame(summary(dd_tax_age_ma_w1))
ame_dd_tax_age_w1$age_rec_w1 <- as.character(ame_dd_tax_age_w1$age_rec_w1)
ame_dd_tax_age_w1$AME <- as.numeric(ame_dd_tax_age_w1$AME)
ame_dd_tax_age_w1$SE <- as.numeric(ame_dd_tax_age_w1$SE)
ame_dd_tax_age_w1$Treatment <- ame_dd_tax_age_w1$factor
ame_dd_tax_age_w1$upper95 <- ame_dd_tax_age_w1$AME + (ame_dd_tax_age_w1$SE*1.96)
ame_dd_tax_age_w1$lower95 <- ame_dd_tax_age_w1$AME - (ame_dd_tax_age_w1$SE*1.96)

ame_dd_tax_age_w1$Treatment[ame_dd_tax_age_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_tax_age_w1$Treatment[ame_dd_tax_age_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_tax_age_w1 <- ggplot(ame_dd_tax_age_w1, aes(colour = age_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = age_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_fill_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_shape_discrete("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +       xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Taxes") + 
      theme(plot.title = element_text(face = "bold"))

# analyze effect of treatment on pension
dd_pen_age_w1 <- lm(exp_pen_w1_z ~ treat*age_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_pen_age_ma_w1 <- margins::margins(dd_pen_age_w1, variables = "treat", at = list(age_rec_w1 = c("Up to 35", "35-50", "51-65", "65+")))
ame_dd_pen_age_w1 <- as.data.frame(summary(dd_pen_age_ma_w1))
ame_dd_pen_age_w1$age_rec_w1 <- as.character(ame_dd_pen_age_w1$age_rec_w1)
ame_dd_pen_age_w1$AME <- as.numeric(ame_dd_pen_age_w1$AME)
ame_dd_pen_age_w1$SE <- as.numeric(ame_dd_pen_age_w1$SE)
ame_dd_pen_age_w1$Treatment <- ame_dd_pen_age_w1$factor
ame_dd_pen_age_w1$upper95 <- ame_dd_pen_age_w1$AME + (ame_dd_pen_age_w1$SE*1.96)
ame_dd_pen_age_w1$lower95 <- ame_dd_pen_age_w1$AME - (ame_dd_pen_age_w1$SE*1.96)

ame_dd_pen_age_w1$Treatment[ame_dd_pen_age_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_pen_age_w1$Treatment[ame_dd_pen_age_w1$Treatment=="treat3"] <- "Unsustainable"

gg_ame_dd_pen_age_w1 <- ggplot(ame_dd_pen_age_w1, aes(colour = age_rec_w1)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = age_rec_w1), position = position_dodge(width=0.5), size=2) +
  theme_bw() + scale_color_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_fill_grey("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) + 
  scale_shape_discrete("Age", breaks=c("Up to 35", "35-50", "51-65", "65+")) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
  scale_x_continuous(limits = c(-0.55, 0.55), breaks = c(-0.5, -0.25, 0, 0.25, 0.5), labels = c(-0.5, -0.25, 0, 0.25, 0.5)) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Pensions") + 
      theme(plot.title = element_text(face = "bold"))

exp_hte_graph_age_w1 <- ggarrange(gg_ame_dd_tax_age_w1, 
                                  gg_ame_dd_pen_age_w1 + 
                                          theme(axis.text.y = element_blank(),
                                                axis.title.y = element_blank()), 
                                  gg_ame_dd_nhs_qual_age_w1, 
                                  gg_ame_dd_nhs_costs_age_w1 + 
                                          theme(axis.text.y = element_blank(),
                                                axis.title.y = element_blank()), 
                                  gg_ame_dd_gdp_age_w1, 
                                  gg_ame_dd_infl_age_w1 + 
                                          theme(axis.text.y = element_blank(),
                                                axis.title.y = element_blank()), nrow=3, ncol=2, common.legend = T,  legend="bottom", widths = c(1, 0.75))
exp_hte_graph_age_w1

ggsave(exp_hte_graph_age_w1, width = 18, height = 20, units = c("cm"), file ="appendix/FigureF8.pdf")
```

## Figure F.9

```{r, results = 'asis', message=F, echo=FALSE}
# Calculate average debt concern by age group
df_debt_avg <- debt_w1 %>%
  mutate(age_rec_w1 = debt_w1$age_rec_w1,
         debt_index_rescaled = debt_index_w1 - 3) %>%  # Rescale to 0-9
  group_by(age_rec_w1) %>%
  summarise(avg_debt_aversion = mean(debt_index_rescaled, na.rm = TRUE)) %>%
  filter(!is.na(age_rec_w1))  # Remove any NA age groups
# Ensure age groups are in the correct order
df_debt_avg$age_rec_w1 <- factor(df_debt_avg$age_rec_w1, 
                                  levels = c("Up to 35", "35-50", "51-65", "65+"))
# Create color palette (4 categories to match your age groups)
age_colors <- c("grey20", "grey35", "grey50", "grey65")
# Create the plot
gg_debt_aversion <- ggplot(df_debt_avg, aes(x = age_rec_w1, y = avg_debt_aversion, fill = age_rec_w1)) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = age_colors) +
  labs(y = "Average Debt Aversion (Index, 0-9)", 
       x = "Age Category",
       title = "Debt Aversion") +
  theme_minimal() +
  theme(legend.position = "none",
        axis.text.x = element_text(angle = 45, hjust = 1),
        plot.title = element_text(face = "bold")) +
  geom_text(aes(label = round(avg_debt_aversion, 2)), 
            size = 3, 
            color = "black", 
            position = position_stack(vjust = 0.5))

# Calculate average debt concern by age group
df_debt_concern_avg <- debt_w1 %>%
  mutate(age_rec_w1 = debt_w1$age_rec_w1) %>%
  group_by(age_rec_w1) %>%
  summarise(avg_debt_concern = mean(debt_post_w1, na.rm = TRUE)) %>%
  filter(!is.na(age_rec_w1))  # Remove any NA age groups
# Ensure age groups are in the correct order
df_debt_concern_avg$age_rec_w1 <- factor(df_debt_concern_avg$age_rec_w1, 
                                          levels = c("Up to 35", "35-50", "51-65", "65+"))
# Create color palette (4 categories to match your age groups)
age_colors <- c("grey20", "grey35", "grey50", "grey65")
# Create the plot
gg_debt_concern <- ggplot(df_debt_concern_avg, aes(x = age_rec_w1, y = avg_debt_concern, fill = age_rec_w1)) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = age_colors) +
  labs(y = "Average Debt Concern (0-5)", 
       x = "Age Category",
       title = "Concern") +
  theme_minimal() +
  theme(legend.position = "none",
        axis.text.x = element_text(angle = 45, hjust = 1),
        plot.title = element_text(face = "bold")) +
  geom_text(aes(label = round(avg_debt_concern, 2)), 
            size = 3, 
            color = "black", 
            position = position_stack(vjust = 0.5))
# Combine the graphs
graph_age_additional <- ggarrange(gg_debt_concern, gg_debt_aversion, nrow = 1, ncol=2)
ggsave(graph_age_additional, width = 25, height = 15, units = c("cm"), file ="appendix/FigureF9.pdf")
```

## Figure F.10:

```{r, results = 'asis', message=F, echo=FALSE}
# Figure 2 for age 

debt_w1$age_rec_w1 <- factor(debt_w1$age_rec_w1, 
                             levels = c("Up to 35", "35-50", "51-65", "65+"))

# subset only to control group
debt_w1_rec <- debt_w1[which(debt_w1$treat_w1==1),]

# priority given to debt by age...
debt_CC_rec_w1_df <- datasummary_crosstab(debt_CC_rec_w1 ~ age_rec_w1, statistic = 1 ~ Percent("col"), data = debt_w1_rec, output = 'data.frame')
debt_immi_rec_w1_df <- datasummary_crosstab(debt_immi_rec_w1 ~ age_rec_w1, statistic = 1 ~ Percent("col"), data = debt_w1_rec, output = 'data.frame')
debt_nhs_rec_w1_df <- datasummary_crosstab(debt_nhs_rec_w1 ~ age_rec_w1, statistic = 1 ~ Percent("col"), data = debt_w1_rec, output = 'data.frame')

debt_CC_rec_w1_df <- debt_CC_rec_w1_df %>% rename(priority=debt_CC_rec_w1)
debt_CC_rec_w1_df$Topic <- "Climate change"
debt_immi_rec_w1_df <- debt_immi_rec_w1_df %>% rename(priority=debt_immi_rec_w1)
debt_immi_rec_w1_df$Topic <- "Immigration"
debt_nhs_rec_w1_df <- debt_nhs_rec_w1_df %>% rename(priority=debt_nhs_rec_w1)
debt_nhs_rec_w1_df$Topic <- "NHS"

df_priority <- rbind(debt_CC_rec_w1_df[,-2], debt_immi_rec_w1_df[,-2], debt_nhs_rec_w1_df[,-2])

# Get the age category column names
age_cols <- names(df_priority)[!names(df_priority) %in% c("priority", "Topic")]

df_priority <- df_priority %>% 
  pivot_longer(
    cols = all_of(age_cols), 
    names_to = "age",
    values_to = "value")

df_priority <- df_priority %>% subset(priority!="All") %>% mutate(value = as.numeric(value))
df_priority$value <- df_priority$value/100
df_priority$priority <- ifelse(df_priority$priority==0, "Debt is not priority", ifelse(df_priority$priority==1, "Debt is priority", NA))

# Order age categories properly
df_priority$age <- factor(df_priority$age, levels = c("Up to 35", "35-50", "51-65", "65+"))

# Create color palette for age categories
age_colors <- c("grey20", "grey40", "grey60", "grey80")

gg_prio_simple <- ggplot(df_priority[which(df_priority$priority == "Debt is priority"),], aes(x = age, y = value, fill = age)) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = age_colors) +
  facet_grid(~ Topic, scales = "free") +
  labs(y = "Share", x = "Age Category") +
  theme_minimal() +
  theme(legend.position = "none",
        axis.text.x = element_text(angle = 45, hjust = 1)) +
  geom_text(aes(label = round(value, 2)), size = 2.5, color = "black", position = position_stack(vjust = 0.5)) +
  ylim(0, 0.62)

# how often given prio by age? 
debt_w1_rec$sum_debt_prio <- debt_w1_rec$debt_CC_rec_w1+ debt_w1_rec$debt_immi_rec_w1 + debt_w1_rec$debt_nhs_rec_w1
debt_w1_rec$sum_debt_prio_rec <- ifelse(debt_w1_rec$sum_debt_prio==3, "Debt over all 3", ifelse(debt_w1_rec$sum_debt_prio==2, "Debt over at least 2", ifelse(debt_w1_rec$sum_debt_prio==0, "Never prio debt", NA)))

sum_debt_prio_rec_w1_df <- datasummary_crosstab(sum_debt_prio_rec ~ age_rec_w1, statistic = 1 ~ Percent("col"), data = debt_w1_rec, output = 'data.frame')

sum_debt_prio_rec_w1_df <- sum_debt_prio_rec_w1_df %>% 
  pivot_longer(
    cols = `Up to 35`:`65+`, 
    names_to = "age",
    values_to = "value")
sum_debt_prio_rec_w1_df <- sum_debt_prio_rec_w1_df %>% subset(sum_debt_prio_rec!="All") %>% mutate(value = as.numeric(value))
sum_debt_prio_rec_w1_df$value <- sum_debt_prio_rec_w1_df$value/100
sum_debt_prio_rec_w1_df <- sum_debt_prio_rec_w1_df[,-2]

# Order age categories properly in the summary data too
sum_debt_prio_rec_w1_df$age <- factor(sum_debt_prio_rec_w1_df$age, levels = c("Up to 35", "35-50", "51-65", "65+"))

gg_prio_comp <- ggplot(sum_debt_prio_rec_w1_df, aes(x = age, y = value, fill = age)) + 
      geom_bar(stat = "identity") +
      scale_fill_manual(values = age_colors) +
      facet_grid(~ sum_debt_prio_rec, scales = "free") + 
      labs(y = "Share", x = "Age Category") + 
      theme_minimal() + 
      theme(legend.position = "none",
            axis.text.x = element_text(angle = 45, hjust = 1)) +
      geom_text(aes(label = round(value, 2)), size = 2.5, color="black", position = position_stack(vjust = 0.5)) + 
      ylim(0,0.62)

prio_graph <- ggarrange(gg_prio_simple, gg_prio_comp, nrow = 1, ncol=2)
prio_graph

ggsave(prio_graph, width = 25, height = 15, units = c("cm"), file ="appendix/FigureF10.pdf")
```

## Figure F.11: 

```{r, results = 'asis', message=F, echo=FALSE}
# plot results from the allocation exercise 
# survey 1

# Create separate datasets for each age category manually
# Up to 35
allocation_w1_Young <- datasummary(alloc_debt_w1 + alloc_cuts_edu_w1 + alloc_cuts_benefits_w1 + alloc_tax_income_w1 + alloc_tax_vat_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1_rec[which(debt_w1_rec$age_rec_w1 == "Up to 35"),], output = 'data.frame', fmt = 3)
allocation_w1_Young$sample <- "Up to 35"
colnames(allocation_w1_Young)[1] <- "Variable"

# 35-50
allocation_w1_Mid <- datasummary(alloc_debt_w1 + alloc_cuts_edu_w1 + alloc_cuts_benefits_w1 + alloc_tax_income_w1 + alloc_tax_vat_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1_rec[which(debt_w1_rec$age_rec_w1 == "35-50"),], output = 'data.frame', fmt = 3)
allocation_w1_Mid$sample <- "35-50"
colnames(allocation_w1_Mid)[1] <- "Variable"

# 51-65
allocation_w1_Senior <- datasummary(alloc_debt_w1 + alloc_cuts_edu_w1 + alloc_cuts_benefits_w1 + alloc_tax_income_w1 + alloc_tax_vat_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1_rec[which(debt_w1_rec$age_rec_w1 == "51-65"),], output = 'data.frame', fmt = 3)
allocation_w1_Senior$sample <- "51-65"
colnames(allocation_w1_Senior)[1] <- "Variable"

# 65+
allocation_w1_Elder <- datasummary(alloc_debt_w1 + alloc_cuts_edu_w1 + alloc_cuts_benefits_w1 + alloc_tax_income_w1 + alloc_tax_vat_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1_rec[which(debt_w1_rec$age_rec_w1 == "65+"),], output = 'data.frame', fmt = 3)
allocation_w1_Elder$sample <- "65+"
colnames(allocation_w1_Elder)[1] <- "Variable"

# combine the results
allocation_w1 <- rbind(allocation_w1_Young, allocation_w1_Mid, allocation_w1_Senior, allocation_w1_Elder)
allocation_w1$mean <- (as.numeric(allocation_w1$mean))

# Update factor levels for age categories
allocation_w1$sample <- factor(allocation_w1$sample, levels = c("Up to 35", "35-50", "51-65", "65+"))
allocation_w1$Variable <- factor(allocation_w1$Variable , levels = c("alloc_cuts_edu_w1", "alloc_cuts_benefits_w1","alloc_tax_vat_w1", "alloc_tax_income_w1","alloc_debt_w1"))

# plot a graph allocation exercise - updated colors for age categories
graph_allocation_w1 <- ggplot(allocation_w1, aes(x = mean, y = Variable, fill = sample)) + 
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey20", "grey40", "grey60", "grey80"), 
                        breaks = c("Up to 35", "35-50", "51-65", "65+"), 
                        labels = c("Up to 35", "35-50", "51-65", "65+")) +
      scale_y_discrete(labels = c("Cutting edu spending", "Cutting benefits", "Increasing VAT", "Increasing inc tax\nprogressively", "Increasing debt")) +
      theme_minimal() +
      labs(y = "", x = "Average points", fill = NULL) +
      ggtitle("NHS Funding Exercise") + 
      theme(plot.title = element_text(face = "bold")) +
      xlim(0, 37)
#graph_allocation_w1
```

```{r, results = 'asis', message=F, echo=FALSE}
# plot results from the qvsr  

# Create separate datasets for each age category manually
# Up to 35
qvsr_Young <- datasummary(qvsr_cc + qvsr_nhs + qvsr_inflation + qvsr_immi + qvsr_debt ~ mean*Arguments(na.rm=TRUE), data = debt_w2_w3_qvsr[which(debt_w2_w3_qvsr$age_rec_w2 == "Up to 35"),], output = 'data.frame', fmt = 3)
qvsr_Young$sample <- "Up to 35"
colnames(qvsr_Young)[1] <- "Variable"

# 35-50
qvsr_Mid <- datasummary(qvsr_cc + qvsr_nhs + qvsr_inflation + qvsr_immi + qvsr_debt ~ mean*Arguments(na.rm=TRUE), data = debt_w2_w3_qvsr[which(debt_w2_w3_qvsr$age_rec_w2 == "35-50"),], output = 'data.frame', fmt = 3)
qvsr_Mid$sample <- "35-50"
colnames(qvsr_Mid)[1] <- "Variable"

# 51-65
qvsr_Senior <- datasummary(qvsr_cc + qvsr_nhs + qvsr_inflation + qvsr_immi + qvsr_debt ~ mean*Arguments(na.rm=TRUE), data = debt_w2_w3_qvsr[which(debt_w2_w3_qvsr$age_rec_w2 == "51-65"),], output = 'data.frame', fmt = 3)
qvsr_Senior$sample <- "51-65"
colnames(qvsr_Senior)[1] <- "Variable"

# 65+
qvsr_Elder <- datasummary(qvsr_cc + qvsr_nhs + qvsr_inflation + qvsr_immi + qvsr_debt ~ mean*Arguments(na.rm=TRUE), data = debt_w2_w3_qvsr[which(debt_w2_w3_qvsr$age_rec_w2 == "65+"),], output = 'data.frame', fmt = 3)
qvsr_Elder$sample <- "65+"
colnames(qvsr_Elder)[1] <- "Variable"

# combine the results
qvsr_dist <- rbind(qvsr_Young, qvsr_Mid, qvsr_Senior, qvsr_Elder)
qvsr_dist$mean <- (as.numeric(qvsr_dist$mean))
qvsr_dist$sample <- factor(qvsr_dist$sample, levels = c("Up to 35", "35-50", "51-65", "65+"))
qvsr_dist$Variable <- factor(qvsr_dist$Variable, levels = c("qvsr_inflation","qvsr_immi","qvsr_nhs","qvsr_cc","qvsr_debt"))

# plot a graph for qvsr
graph_qvsr <- ggplot(qvsr_dist, aes(x = mean, y = Variable, fill = sample)) + 
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey20", "grey40", "grey60", "grey80"), 
                        breaks = c("Up to 35", "35-50", "51-65", "65+"), 
                        labels = c("Up to 35", "35-50", "51-65", "65+")) +
      scale_y_discrete(labels = c("Inflation support","Immigration","NHS", "Climate change", "Debt")) +
      theme_minimal() +
      labs(y = "", x = "Average votes", fill = NULL) +
      ggtitle("QVSR") + 
      theme(plot.title = element_text(face = "bold")) +
      xlim(0, 3)
#graph_qvsr
```

```{r, results = 'asis', message=F, echo=FALSE}
# combine the graphs
graph_exercises <- ggarrange(graph_allocation_w1, graph_qvsr, 
                         common.legend = T, legend = "bottom", nrow = 1, ncol=2)

# save the combined graph
ggsave(graph_exercises, width = 18, height = 12, units = c("cm"), file ="appendix/FigureF11.pdf")
graph_exercises
```

### Tables F1 and F2

```{r, results = 'asis', message=F, echo=FALSE}
## regressions for age
debt_w2$age_rec_w2 <- factor(debt_w2$age_rec_w2, 
                              levels = c("Up to 35", "35-50", "51-65", "65+"))

debt_w2_w3_qvsr$age_rec_w2 <- factor(debt_w2_w3_qvsr$age_rec_w2, 
                              levels = c("Up to 35", "35-50", "51-65", "65+"))


# Store all Survey 1 models
m1_w1 <- lm(debt_index_z_w1 ~ age_w1 + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m2_w1 <- lm(debt_index_z_w1 ~ age_w1 + I(age_w1^2) + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m3_w1 <- lm(debt_index_z_w1 ~ factor(age_rec_w1) + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m4_w1 <- lm(debt_CC_rec_z_w1 ~ age_w1 + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m5_w1 <- lm(debt_CC_rec_z_w1 ~ age_w1 + I(age_w1^2) + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m6_w1 <- lm(debt_CC_rec_z_w1 ~ factor(age_rec_w1) + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m7_w1 <- lm(debt_nhs_rec_z_w1 ~ age_w1 + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m8_w1 <- lm(debt_nhs_rec_z_w1 ~ age_w1 + I(age_w1^2) + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m9_w1 <- lm(debt_nhs_rec_z_w1 ~ factor(age_rec_w1) + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m10_w1 <- lm(debt_immi_rec_z_w1 ~ age_w1 + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m11_w1 <- lm(debt_immi_rec_z_w1 ~ age_w1 + I(age_w1^2) + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m12_w1 <- lm(debt_immi_rec_z_w1 ~ factor(age_rec_w1) + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m13_w1 <- lm(alloc_debt_z_w1 ~ age_w1 + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m14_w1 <- lm(alloc_debt_z_w1 ~ age_w1 + I(age_w1^2) + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m15_w1 <- lm(alloc_debt_z_w1 ~ factor(age_rec_w1) + income_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)

# Store all Survey 2 models
m1_w2 <- lm(debt_index_z_w2 ~ age_w2 + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m2_w2 <- lm(debt_index_z_w2 ~ age_w2 + I(age_w2^2) + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m3_w2 <- lm(debt_index_z_w2 ~ factor(age_rec_w2) + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m4_w2 <- lm(debt_CC_rec_z_w2 ~ age_w2 + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m5_w2 <- lm(debt_CC_rec_z_w2 ~ age_w2 + I(age_w2^2) + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m6_w2 <- lm(debt_CC_rec_z_w2 ~ factor(age_rec_w2) + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m7_w2 <- lm(debt_nhs_rec_z_w2 ~ age_w2 + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m8_w2 <- lm(debt_nhs_rec_z_w2 ~ age_w2 + I(age_w2^2) + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m9_w2 <- lm(debt_nhs_rec_z_w2 ~ factor(age_rec_w2) + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m10_w2 <- lm(debt_immi_rec_z_w2 ~ age_w2 + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m11_w2 <- lm(debt_immi_rec_z_w2 ~ age_w2 + I(age_w2^2) + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m12_w2 <- lm(debt_immi_rec_z_w2 ~ factor(age_rec_w2) + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m13_w2 <- lm(debt_infl_rec_z_w2 ~ age_w2 + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m14_w2 <- lm(debt_infl_rec_z_w2 ~ age_w2 + I(age_w2^2) + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m15_w2 <- lm(debt_infl_rec_z_w2 ~ factor(age_rec_w2) + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m16_w2 <- lm(alloc_debt_z_w2 ~ age_w2 + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m17_w2 <- lm(alloc_debt_z_w2 ~ age_w2 + I(age_w2^2) + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m18_w2 <- lm(alloc_debt_z_w2 ~ factor(age_rec_w2) + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m19_w2 <- lm(qvsr_debt_z ~ age_w2 + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2_w3_qvsr)
m20_w2 <- lm(qvsr_debt_z ~ age_w2 + I(age_w2^2) + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2_w3_qvsr)
m21_w2 <- lm(qvsr_debt_z ~ factor(age_rec_w2) + income_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2_w3_qvsr)

# Define goodness-of-fit measures
gm <- c("r.squared", "adj.r.squared", "nobs")

cm <- c(
  # Age variables for w1
  "age_w1" = "Age",
  "I(age_w1^2)" = "Age²",
  
  # Age variables for w2
  "age_w2" = "Age",
  "I(age_w2^2)" = "Age²",
  
  # Age categories for w1 (reference is "Up to 35")
  "factor(age_rec_w1)35-50" = "35-50",
  "factor(age_rec_w1)51-65" = "51-65",
  "factor(age_rec_w1)65+" = "65+",
  
  # Age categories for w2 (reference is "Up to 35")
  "factor(age_rec_w2)35-50" = "35-50",
  "factor(age_rec_w2)51-65" = "51-65",
  "factor(age_rec_w2)65+" = "65+"
)

# Table F1: Debt Index and Trade-offs (up to Immi Trade-off)
panels_F1 <- list(
  "Panel A: Survey 1" = list(
    "Debt Index (1)" = m1_w1,
    "Debt Index (2)" = m2_w1,
    "Debt Index (3)" = m3_w1,
    "CC Trade-off (1)" = m4_w1,
    "CC Trade-off (2)" = m5_w1,
    "CC Trade-off (3)" = m6_w1,
    "NHS Trade-off (1)" = m7_w1,
    "NHS Trade-off (2)" = m8_w1,
    "NHS Trade-off (3)" = m9_w1,
    "Immi Trade-off (1)" = m10_w1,
    "Immi Trade-off (2)" = m11_w1,
    "Immi Trade-off (3)" = m12_w1
  ),
  "Panel B: Survey 2" = list(
    "Debt Index (1)" = m1_w2,
    "Debt Index (2)" = m2_w2,
    "Debt Index (3)" = m3_w2,
    "CC Trade-off (1)" = m4_w2,
    "CC Trade-off (2)" = m5_w2,
    "CC Trade-off (3)" = m6_w2,
    "NHS Trade-off (1)" = m7_w2,
    "NHS Trade-off (2)" = m8_w2,
    "NHS Trade-off (3)" = m9_w2,
    "Immi Trade-off (1)" = m10_w2,
    "Immi Trade-off (2)" = m11_w2,
    "Immi Trade-off (3)" = m12_w2,
    "Infl Trade-off (1)" = m13_w2,
    "Infl Trade-off (2)" = m14_w2,
    "Infl Trade-off (3)" = m15_w2
  )
)

# Table F2: NHS Exercise and QVSR
panels_F2 <- list(
  "Panel A: Survey 1" = list(
    "NHS Exercise (1)" = m13_w1,
    "NHS Exercise (2)" = m14_w1,
    "NHS Exercise (3)" = m15_w1
  ),
  "Panel B: Survey 2" = list(
    "NHS Exercise (1)" = m16_w2,
    "NHS Exercise (2)" = m17_w2,
    "NHS Exercise (3)" = m18_w2,
    "QVSR (1)" = m19_w2,
    "QVSR (2)" = m20_w2,
    "QVSR (3)" = m21_w2
  )
)

# Table F1
regressions_age_F1 <- modelsummary(
  panels_F1,
  shape = "rbind",
  gof_map = gm,
  stars = TRUE,
  title = "Age and Preferences for Fiscal Consolidation: Debt Aversion Index and Trade-offs",
  coef_map = cm,
  output = "appendix/TableF1.tex"
)

# Table F2
regressions_age_F2 <- modelsummary(
  panels_F2,
  shape = "rbind",
  gof_map = gm,
  stars = TRUE,
  title = "Age and Preferences for Fiscal Consolidation: NHS Exercise and QVSR",
  coef_map = cm,
  output = "appendix/TableF2.tex"
)
```

## Figure F.12

```{r, results = 'asis', message=F, echo=FALSE}
# Calculate average debt concern by income group
df_debt_avg_income <- debt_w1 %>%
  mutate(income_cat_w1 = debt_w1$income_cat_w1,
         debt_index_rescaled = debt_index_w1 - 3) %>%  # Rescale to 0-9
  group_by(income_cat_w1) %>%
  summarise(avg_debt_aversion = mean(debt_index_rescaled, na.rm = TRUE)) %>%
  filter(!is.na(income_cat_w1))  # Remove any NA income groups

# Ensure income groups are in the correct order
df_debt_avg_income$income_cat_w1 <- factor(df_debt_avg_income$income_cat_w1, 
                                            levels = c("Low", "Middle", "High"))

# Create color palette (3 categories to match your income groups)
income_colors <- c("grey20", "grey50", "grey80")

# Create the plot
gg_debt_aversion_income <- ggplot(df_debt_avg_income, aes(x = income_cat_w1, y = avg_debt_aversion, fill = income_cat_w1)) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = income_colors) +
  labs(y = "Average Debt Aversion (Index, 0-9)", 
       x = "Income Category",
       title = "Income") +
  theme_minimal() +
  theme(legend.position = "none",
        axis.text.x = element_text(angle = 45, hjust = 1),
        plot.title = element_text(face = "bold")) +
  geom_text(aes(label = round(avg_debt_aversion, 2)), 
            size = 3, 
            color = "black", 
            position = position_stack(vjust = 0.5))

# Calculate average debt concern by income group
df_debt_concern_avg_income <- debt_w1 %>%
  mutate(income_cat_w1 = debt_w1$income_cat_w1) %>%
  group_by(income_cat_w1) %>%
  summarise(avg_debt_concern = mean(debt_post_w1, na.rm = TRUE)) %>%
  filter(!is.na(income_cat_w1))  # Remove any NA income groups

# Ensure income groups are in the correct order
df_debt_concern_avg_income$income_cat_w1 <- factor(df_debt_concern_avg_income$income_cat_w1, 
                                                     levels = c("Low", "Middle", "High"))

# Create color palette (3 categories to match your income groups)
income_colors <- c("grey20", "grey50", "grey80")

# Create the plot
gg_debt_concern_income <- ggplot(df_debt_concern_avg_income, aes(x = income_cat_w1, y = avg_debt_concern, fill = income_cat_w1)) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = income_colors) +
  labs(y = "Average Debt Concern (0-5)", 
       x = "Income Category",
       title = "Income") +
  theme_minimal() +
   theme(legend.position = "none",
        axis.text.x = element_text(angle = 45, hjust = 1),
        plot.title = element_text(face = "bold")) +
  geom_text(aes(label = round(avg_debt_concern, 2)), 
            size = 3, 
            color = "black", 
            position = position_stack(vjust = 0.5))

graph_income_additional <- ggarrange(gg_debt_concern_income, gg_debt_aversion_income, nrow = 1, ncol=2)
ggsave(graph_income_additional, width = 25, height = 15, units = c("cm"), file ="appendix/FigureF12.pdf")
```

### Figure 13

```{r, results = 'asis', message=F, echo=FALSE}
debt_w1$income_cat_w1 <- factor(debt_w1$income_cat_w1, 
                                   levels = c("Low", "Middle", "High"))

# subset only to control group
debt_w1_rec <- debt_w1[which(debt_w1$treat_w1==1),]

# priority given to debt by income...
debt_CC_rec_w1_df <- datasummary_crosstab(debt_CC_rec_w1 ~ income_cat_w1, statistic = 1 ~ Percent("col"), data = debt_w1_rec, output = 'data.frame')
debt_immi_rec_w1_df <- datasummary_crosstab(debt_immi_rec_w1 ~ income_cat_w1, statistic = 1 ~ Percent("col"), data = debt_w1_rec, output = 'data.frame')
debt_nhs_rec_w1_df <- datasummary_crosstab(debt_nhs_rec_w1 ~ income_cat_w1, statistic = 1 ~ Percent("col"), data = debt_w1_rec, output = 'data.frame')

debt_CC_rec_w1_df <- debt_CC_rec_w1_df %>% rename(priority=debt_CC_rec_w1)
debt_CC_rec_w1_df$Topic <- "Climate change"
debt_immi_rec_w1_df <- debt_immi_rec_w1_df %>% rename(priority=debt_immi_rec_w1)
debt_immi_rec_w1_df$Topic <- "Immigration"
debt_nhs_rec_w1_df <- debt_nhs_rec_w1_df %>% rename(priority=debt_nhs_rec_w1)
debt_nhs_rec_w1_df$Topic <- "NHS"

df_priority <- rbind(debt_CC_rec_w1_df[,-2], debt_immi_rec_w1_df[,-2], debt_nhs_rec_w1_df[,-2])

# Get the income category column names (adjust these based on your actual income categories)
income_cols <- names(df_priority)[!names(df_priority) %in% c("priority", "Topic")]

df_priority <- df_priority %>% 
  pivot_longer(
    cols = all_of(income_cols), 
    names_to = "income",
    values_to = "value")

df_priority <- df_priority %>% subset(priority!="All") %>% mutate_at(4, as.numeric)
df_priority$value <- df_priority$value/100
df_priority$priority <- ifelse(df_priority$priority==0, "Debt is not priority", ifelse(df_priority$priority==1, "Debt is priority", NA))

# Create color palette for income categories (adjust number of colors based on your income categories)
income_colors <- c("grey20", "grey40", "grey60", "grey80")  # Adjust based on number of income categories

df_priority$income <- factor(df_priority$income, 
                                            levels = c("Low", "Middle", "High"))

gg_prio_simple <- ggplot(df_priority[which(df_priority$priority == "Debt is priority"),], aes(x = income, y = value, fill = income)) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = income_colors) +
  facet_grid(~ Topic, scales = "free") +
  labs(y = "Share", x = "Income Category") +
  theme_minimal() +
  theme(legend.position = "none",
        axis.text.x = element_text(angle = 45, hjust = 1)) +  # Rotate x-axis labels if needed
  geom_text(aes(label = round(value, 2)), size = 2.5, color = "black", position = position_stack(vjust = 0.5)) +
  ylim(0, 0.61)

# how often given prio by income? 
debt_w1_rec$sum_debt_prio <- debt_w1_rec$debt_CC_rec_w1+ debt_w1_rec$debt_immi_rec_w1 + debt_w1_rec$debt_nhs_rec_w1
debt_w1_rec$sum_debt_prio_rec <- ifelse(debt_w1_rec$sum_debt_prio==3, "Debt over all 3", ifelse(debt_w1_rec$sum_debt_prio==2, "Debt over at least 2", ifelse(debt_w1_rec$sum_debt_prio==0, "Never prio debt", NA)))

sum_debt_prio_rec_w1_df <- datasummary_crosstab(sum_debt_prio_rec ~ income_cat_w1, statistic = 1 ~ Percent("col"), data = debt_w1_rec, output = 'data.frame')

sum_debt_prio_rec_w1_df <- sum_debt_prio_rec_w1_df %>% 
  pivot_longer(
    cols = `Low`:`High`, 
    names_to = "income",
    values_to = "value")
sum_debt_prio_rec_w1_df <- sum_debt_prio_rec_w1_df %>% subset(sum_debt_prio_rec!="All") %>% mutate_at(4, as.numeric)
sum_debt_prio_rec_w1_df$value <- sum_debt_prio_rec_w1_df$value/100
sum_debt_prio_rec_w1_df <- sum_debt_prio_rec_w1_df[,-2]


sum_debt_prio_rec_w1_df$income <- factor(sum_debt_prio_rec_w1_df$income, 
                                            levels = c("Low", "Middle", "High"))

gg_prio_comp <- ggplot(sum_debt_prio_rec_w1_df, aes(x = income, y = value, fill = income)) + 
      geom_bar(stat = "identity") +
      scale_fill_manual(values = income_colors) +
      facet_grid(~ sum_debt_prio_rec, scales = "free") + 
      labs(y = "Share", x = "Income Category") + 
      theme_minimal() + 
      theme(legend.position = "none",
            axis.text.x = element_text(angle = 45, hjust = 1)) +  # Rotate x-axis labels if needed
      geom_text(aes(label = round(value, 2)), size = 2.5, color="black", position = position_stack(vjust = 0.5)) + 
      ylim(0,0.61)

prio_graph <- ggarrange(gg_prio_simple, gg_prio_comp, nrow = 1, ncol=2)
prio_graph

ggsave(prio_graph, width = 25, height = 15, units = c("cm"), file ="appendix/FigureF13.pdf")
```

## Figure F.14

```{r, results = 'asis', message=F, echo=FALSE}
# plot results from the allocation exercise 
# survey 1

# Create separate datasets for each income category manually
# Low income
allocation_w1_Low <- datasummary(alloc_debt_w1 + alloc_cuts_edu_w1 + alloc_cuts_benefits_w1 + alloc_tax_income_w1 + alloc_tax_vat_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1_rec[which(debt_w1_rec$income_cat_w1 == "Low"),], output = 'data.frame', fmt = 3)
allocation_w1_Low$sample <- "Low"
colnames(allocation_w1_Low)[1] <- "Variable"

# Middle income
allocation_w1_Middle <- datasummary(alloc_debt_w1 + alloc_cuts_edu_w1 + alloc_cuts_benefits_w1 + alloc_tax_income_w1 + alloc_tax_vat_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1_rec[which(debt_w1_rec$income_cat_w1 == "Middle"),], output = 'data.frame', fmt = 3)
allocation_w1_Middle$sample <- "Middle"
colnames(allocation_w1_Middle)[1] <- "Variable"

# High income
allocation_w1_High <- datasummary(alloc_debt_w1 + alloc_cuts_edu_w1 + alloc_cuts_benefits_w1 + alloc_tax_income_w1 + alloc_tax_vat_w1 ~ mean*Arguments(na.rm=TRUE), data = debt_w1_rec[which(debt_w1_rec$income_cat_w1 == "High"),], output = 'data.frame', fmt = 3)
allocation_w1_High$sample <- "High"
colnames(allocation_w1_High)[1] <- "Variable"

# combine the results
allocation_w1 <- rbind(allocation_w1_Low, allocation_w1_Middle, allocation_w1_High)
allocation_w1$mean <- (as.numeric(allocation_w1$mean))

# Update factor levels for income categories
allocation_w1$sample <- factor(allocation_w1$sample, levels = c("Low", "Middle", "High"))
allocation_w1$Variable <- factor(allocation_w1$Variable , levels = c("alloc_cuts_edu_w1", "alloc_cuts_benefits_w1","alloc_tax_vat_w1", "alloc_tax_income_w1","alloc_debt_w1"))

# plot a graph allocation exercise - updated colors for income categories
graph_allocation_w1 <- ggplot(allocation_w1, aes(x = mean, y = Variable, fill = sample)) + 
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey20", "grey50", "grey80"), 
                        breaks = c("Low", "Middle", "High"), 
                        labels = c("Low", "Middle", "High")) +
      scale_y_discrete(labels = c("Cutting edu spending", "Cutting benefits", "Increasing VAT", "Increasing inc tax\nprogressively", "Increasing debt")) +
      theme_minimal() +
      labs(y = "", x = "Average points", fill = NULL) +
      ggtitle("NHS Funding Exercise") + 
      theme(plot.title = element_text(face = "bold")) +
      xlim(0, 37)
#graph_allocation_w1
```

```{r, results = 'asis', message=F, echo=FALSE}
# plot results from the qvsr  

# Create separate datasets for each income category manually
# Low income
qvsr_Low <- datasummary(qvsr_cc + qvsr_nhs + qvsr_inflation + qvsr_immi + qvsr_debt ~ mean*Arguments(na.rm=TRUE), data = debt_w2_w3_qvsr[which(debt_w2_w3_qvsr$income_cat_w2 == "Low"),], output = 'data.frame', fmt = 3)
qvsr_Low$sample <- "Low"
colnames(qvsr_Low)[1] <- "Variable"

# Middle income
qvsr_Middle <- datasummary(qvsr_cc + qvsr_nhs + qvsr_inflation + qvsr_immi + qvsr_debt ~ mean*Arguments(na.rm=TRUE), data = debt_w2_w3_qvsr[which(debt_w2_w3_qvsr$income_cat_w2 == "Middle"),], output = 'data.frame', fmt = 3)
qvsr_Middle$sample <- "Middle"
colnames(qvsr_Middle)[1] <- "Variable"

# High income
qvsr_High <- datasummary(qvsr_cc + qvsr_nhs + qvsr_inflation + qvsr_immi + qvsr_debt ~ mean*Arguments(na.rm=TRUE), data = debt_w2_w3_qvsr[which(debt_w2_w3_qvsr$income_cat_w2 == "High"),], output = 'data.frame', fmt = 3)
qvsr_High$sample <- "High"
colnames(qvsr_High)[1] <- "Variable"

# combine the results
qvsr_dist <- rbind(qvsr_Low, qvsr_Middle, qvsr_High)
qvsr_dist$mean <- (as.numeric(qvsr_dist$mean))
qvsr_dist$sample <- factor(qvsr_dist$sample, levels = c("Low", "Middle", "High"))
qvsr_dist$Variable <- factor(qvsr_dist$Variable, levels = c("qvsr_inflation","qvsr_immi","qvsr_nhs","qvsr_cc","qvsr_debt"))

# plot a graph for qvsr
graph_qvsr <- ggplot(qvsr_dist, aes(x = mean, y = Variable, fill = sample)) + 
      geom_bar(stat = "identity", position = "dodge") +
      scale_fill_manual(values = c("grey20", "grey50", "grey80"), 
                        breaks = c("Low", "Middle", "High"), 
                        labels = c("Low", "Middle", "High")) +
      scale_y_discrete(labels = c("Inflation support","Immigration","NHS", "Climate change", "Debt")) +
      theme_minimal() +
      labs(y = "", x = "Average votes", fill = NULL) +
      ggtitle("QVSR") + 
      theme(plot.title = element_text(face = "bold")) +
      xlim(0, 3)
#graph_qvsr
```

```{r, results = 'asis', message=F, echo=FALSE}
# combine the graphs
graph_exercises <- ggarrange(graph_allocation_w1, graph_qvsr, 
                         common.legend = T, legend = "bottom", nrow = 1, ncol=2)

# save the combined graph
ggsave(graph_exercises, width = 18, height = 12, units = c("cm"), file ="appendix/FigureF14.pdf")
```

## Tables F13 and F14

```{r, results = 'asis', message=F, echo=FALSE}
# Set factor levels for categorical income
debt_w1$income_cat_w1 <- factor(debt_w1$income_cat_w1, 
                                levels = c("Low", "Middle", "High"))
debt_w2$income_cat_w2 <- factor(debt_w2$income_cat_w2, 
                                levels = c("Low", "Middle", "High"))
debt_w2_w3_qvsr$income_cat_w2 <- factor(debt_w2_w3_qvsr$income_cat_w2, 
                                levels = c("Low", "Middle", "High"))

#  Store all Survey 1 models
m1_w1 <- lm(debt_index_z_w1 ~ income_w1 + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m2_w1 <- lm(debt_index_z_w1 ~ income_w1 + I(income_w1^2) + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m3_w1 <- lm(debt_index_z_w1 ~ factor(income_cat_w1) + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m4_w1 <- lm(debt_CC_rec_z_w1 ~ income_w1 + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m5_w1 <- lm(debt_CC_rec_z_w1 ~ income_w1 + I(income_w1^2) + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m6_w1 <- lm(debt_CC_rec_z_w1 ~ factor(income_cat_w1) + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m7_w1 <- lm(debt_nhs_rec_z_w1 ~ income_w1 + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m8_w1 <- lm(debt_nhs_rec_z_w1 ~ income_w1 + I(income_w1^2) + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m9_w1 <- lm(debt_nhs_rec_z_w1 ~ factor(income_cat_w1) + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m10_w1 <- lm(debt_immi_rec_z_w1 ~ income_w1 + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m11_w1 <- lm(debt_immi_rec_z_w1 ~ income_w1 + I(income_w1^2) + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m12_w1 <- lm(debt_immi_rec_z_w1 ~ factor(income_cat_w1) + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m13_w1 <- lm(alloc_debt_z_w1 ~ income_w1 + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m14_w1 <- lm(alloc_debt_z_w1 ~ income_w1 + I(income_w1^2) + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)
m15_w1 <- lm(alloc_debt_z_w1 ~ factor(income_cat_w1) + age_w1 + factor(gender_rec_w1) + factor(edu_rec_w1) + factor(party_w1) + factor(treat_w1), data = debt_w1)

# Store all Survey 2 models
m1_w2 <- lm(debt_index_z_w2 ~ income_w2 + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m2_w2 <- lm(debt_index_z_w2 ~ income_w2 + I(income_w2^2) + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m3_w2 <- lm(debt_index_z_w2 ~ factor(income_cat_w2) + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m4_w2 <- lm(debt_CC_rec_z_w2 ~ income_w2 + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m5_w2 <- lm(debt_CC_rec_z_w2 ~ income_w2 + I(income_w2^2) + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m6_w2 <- lm(debt_CC_rec_z_w2 ~ factor(income_cat_w2) + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m7_w2 <- lm(debt_nhs_rec_z_w2 ~ income_w2 + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m8_w2 <- lm(debt_nhs_rec_z_w2 ~ income_w2 + I(income_w2^2) + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m9_w2 <- lm(debt_nhs_rec_z_w2 ~ factor(income_cat_w2) + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m10_w2 <- lm(debt_immi_rec_z_w2 ~ income_w2 + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m11_w2 <- lm(debt_immi_rec_z_w2 ~ income_w2 + I(income_w2^2) + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m12_w2 <- lm(debt_immi_rec_z_w2 ~ factor(income_cat_w2) + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m13_w2 <- lm(debt_infl_rec_z_w2 ~ income_w2 + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m14_w2 <- lm(debt_infl_rec_z_w2 ~ income_w2 + I(income_w2^2) + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m15_w2 <- lm(debt_infl_rec_z_w2 ~ factor(income_cat_w2) + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m16_w2 <- lm(alloc_debt_z_w2 ~ income_w2 + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m17_w2 <- lm(alloc_debt_z_w2 ~ income_w2 + I(income_w2^2) + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m18_w2 <- lm(alloc_debt_z_w2 ~ factor(income_cat_w2) + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2)
m19_w2 <- lm(qvsr_debt_z ~ income_w2 + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2_w3_qvsr)
m20_w2 <- lm(qvsr_debt_z ~ income_w2 + I(income_w2^2) + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2_w3_qvsr)
m21_w2 <- lm(qvsr_debt_z ~ factor(income_cat_w2) + age_w2 + factor(gender_rec_w2) + factor(edu_rec_w2) + factor(party_w2) + factor(treat_w2), data = debt_w2_w3_qvsr)

# Define goodness-of-fit measures
gm <- c("r.squared", "adj.r.squared", "nobs")

# Coefficient map for income variables
cm <- c(
  # Income variables for w1
  "income_w1" = "Income",
  "I(income_w1^2)" = "Income²",
  
  # Income variables for w2
  "income_w2" = "Income",
  "I(income_w2^2)" = "Income²",
  
  # Income categories for w1 (reference is "Low")
  "factor(income_cat_w1)Middle" = "Middle",
  "factor(income_cat_w1)High" = "High",
  
  # Income categories for w2 (reference is "Low")
  "factor(income_cat_w2)Middle" = "Middle",
  "factor(income_cat_w2)High" = "High"
)

# Table F3: Debt Index and Trade-offs (up to Immi Trade-off)
panels_F3 <- list(
  "Panel A: Survey 1" = list(
    "Debt Index (1)" = m1_w1,
    "Debt Index (2)" = m2_w1,
    "Debt Index (3)" = m3_w1,
    "CC Trade-off (1)" = m4_w1,
    "CC Trade-off (2)" = m5_w1,
    "CC Trade-off (3)" = m6_w1,
    "NHS Trade-off (1)" = m7_w1,
    "NHS Trade-off (2)" = m8_w1,
    "NHS Trade-off (3)" = m9_w1,
    "Immi Trade-off (1)" = m10_w1,
    "Immi Trade-off (2)" = m11_w1,
    "Immi Trade-off (3)" = m12_w1
  ),
  "Panel B: Survey 2" = list(
    "Debt Index (1)" = m1_w2,
    "Debt Index (2)" = m2_w2,
    "Debt Index (3)" = m3_w2,
    "CC Trade-off (1)" = m4_w2,
    "CC Trade-off (2)" = m5_w2,
    "CC Trade-off (3)" = m6_w2,
    "NHS Trade-off (1)" = m7_w2,
    "NHS Trade-off (2)" = m8_w2,
    "NHS Trade-off (3)" = m9_w2,
    "Immi Trade-off (1)" = m10_w2,
    "Immi Trade-off (2)" = m11_w2,
    "Immi Trade-off (3)" = m12_w2,
    "Infl Trade-off (1)" = m13_w2,
    "Infl Trade-off (2)" = m14_w2,
    "Infl Trade-off (3)" = m15_w2
  )
)

# Table F4: NHS Exercise and QVSR
panels_F4 <- list(
  "Panel A: Survey 1" = list(
    "NHS Exercise (1)" = m13_w1,
    "NHS Exercise (2)" = m14_w1,
    "NHS Exercise (3)" = m15_w1
  ),
  "Panel B: Survey 2" = list(
    "NHS Exercise (1)" = m16_w2,
    "NHS Exercise (2)" = m17_w2,
    "NHS Exercise (3)" = m18_w2,
    "QVSR (1)" = m19_w2,
    "QVSR (2)" = m20_w2,
    "QVSR (3)" = m21_w2
  )
)

# Table F3
regressions_income_F3 <- modelsummary(
  panels_F3,
  shape = "rbind",
  gof_map = gm,
  stars = TRUE,
  title = "Income and Preferences for Fiscal Consolidation: Debt Aversion Index and Trade-offs",
  coef_map = cm,
  output = "appendix/TableF3.tex"
)

# Table F4
regressions_income_F4 <- modelsummary(
  panels_F4,
  shape = "rbind",
  gof_map = gm,
  stars = TRUE,
  title = "Income and Preferences for Fiscal Consolidation: NHS Exercise and QVSR",
  coef_map = cm,
  output = "appendix/TableF4.tex"
)
```

# Appendix G

## Figure G.1: Results from the placebo tests

```{r, results = 'asis', message=F, echo=FALSE}
dd_china_3 <- lm(china_post_w1 ~ treat + as.factor(china_pre_w1) + as.factor(block_w1), data = debt_w1)

dd_china_2 <- lm(china_post_w2 ~ treat + as.factor(china_pre_w2) + as.factor(block_w2), data = debt_w2)

dd_china_1 <- lm(china_post_w3 ~ treat + as.factor(china_pre_w2) + as.factor(block_w2), data = debt_w2_w3)

# combine results from all waves in one graph
ate_china_all <- multiplot(dd_china_3, dd_china_2, dd_china_1, intercept = FALSE, coefficients = c("treat2", "treat3"), title = "Placebo Check (China)", ylab = "Treatment", xlab = "Average treatment effect", pointSize = 2, innerCI=0, newNames = c("treat2" = "Sustainable", "treat3" = "Unsustainable"), dodgeHeight = 0.85) +
      theme_bw() + scale_x_continuous(breaks = seq(from = -0.2, to = 0.2, by = 0.1), limits = c(-0.19, 0.19)) +
      scale_color_grey(name = "Survey", breaks = c("dd_china_3", "dd_china_2", "dd_china_1"), labels = c("Survey 1", "Survey 2, wave 1", "Survey 2, wave 2"), start = 0.6, end = 0.2, aesthetics = "colour") +
      scale_fill_grey(name = "Survey",  breaks = c("dd_china_3", "dd_china_2", "dd_china_1"), labels = c("Survey 1", "Survey 2, wave 1", "Survey 2, wave 2"), start = 0.6, end = 0.2, aesthetics = "colour") +
      scale_shape_discrete(name = "Survey",  breaks = c("dd_china_3", "dd_china_2", "dd_china_1"), labels = c("Survey 1", "Survey 2, wave 1", "Survey 2, wave 2"))  +
      theme(plot.title = element_text(face = "bold"))

ate_china_all

ggsave(ate_china_all, width = 15, height = 12, units = c("cm"), file ="appendix/FigureG1.pdf")
```

## Figure G.2:

```{r, include = FALSE}
# create figure 3 graph: use the debt aversion index
## people who are certain that debt is a serious issue
## people who are uncertain
## people who are in the middle-of-the-road 

# analyze effect of treatment on debt index by concern for survey 1
dd_index_conc_w1 <- lm(debt_index_z_w1 ~ treat*cert_debt_rec_w1 + as.factor(debt_pre_w1), data = debt_w1)
dd_index_conc_ma_w1 <- margins::margins(dd_index_conc_w1, variables = "treat", at = list(cert_debt_rec_w1 = c("Serious problem", "Uncertain", "Not a serious problem")))
ame_dd_index_conc_w1 <- as.data.frame(summary(dd_index_conc_ma_w1))
ame_dd_index_conc_w1$cert_debt_rec_w1 <- as.character(ame_dd_index_conc_w1$cert_debt_rec_w1)
ame_dd_index_conc_w1$AME <- as.numeric(ame_dd_index_conc_w1$AME)
ame_dd_index_conc_w1$SE <- as.numeric(ame_dd_index_conc_w1$SE)
ame_dd_index_conc_w1$Treatment <- ame_dd_index_conc_w1$factor
ame_dd_index_conc_w1$upper95 <- ame_dd_index_conc_w1$AME + (ame_dd_index_conc_w1$SE*1.96)
ame_dd_index_conc_w1$lower95 <- ame_dd_index_conc_w1$AME - (ame_dd_index_conc_w1$SE*1.96)

ame_dd_index_conc_w1$Treatment[ame_dd_index_conc_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_index_conc_w1$Treatment[ame_dd_index_conc_w1$Treatment=="treat3"] <- "Unsustainable"
ame_dd_index_conc_w1$Survey <- "Survey 1"
names(ame_dd_index_conc_w1)[names(ame_dd_index_conc_w1) == "cert_debt_rec_w1"] <- "cert_debt_rec"

# analyze effect of treatment on debt index by concern for survey 2
dd_index_conc_w2 <- lm(debt_index_z_w2 ~ treat*cert_debt_rec_w2 + as.factor(debt_pre_w2), data = debt_w2)
dd_index_conc_ma_w2 <- margins::margins(dd_index_conc_w2, variables = "treat", at = list(cert_debt_rec_w2 = c("Serious problem", "Uncertain", "Not a serious problem")))
ame_dd_index_conc_w2 <- as.data.frame(summary(dd_index_conc_ma_w2))
ame_dd_index_conc_w2$cert_debt_rec_w2 <- as.character(ame_dd_index_conc_w2$cert_debt_rec_w2)
ame_dd_index_conc_w2$AME <- as.numeric(ame_dd_index_conc_w2$AME)
ame_dd_index_conc_w2$SE <- as.numeric(ame_dd_index_conc_w2$SE)
ame_dd_index_conc_w2$Treatment <- ame_dd_index_conc_w2$factor
ame_dd_index_conc_w2$upper95 <- ame_dd_index_conc_w2$AME + (ame_dd_index_conc_w2$SE*1.96)
ame_dd_index_conc_w2$lower95 <- ame_dd_index_conc_w2$AME - (ame_dd_index_conc_w2$SE*1.96)

ame_dd_index_conc_w2$Treatment[ame_dd_index_conc_w2$Treatment=="treat2"] <- "Sustainable"
ame_dd_index_conc_w2$Treatment[ame_dd_index_conc_w2$Treatment=="treat3"] <- "Unsustainable"
ame_dd_index_conc_w2$Survey <- "Survey 2, Wave 1"
names(ame_dd_index_conc_w2)[names(ame_dd_index_conc_w2) == "cert_debt_rec_w2"] <- "cert_debt_rec"

# analyze effect of treatment on debt index by concern for survey 2, pt 2
dd_index_conc_w3 <- lm(debt_index_z_w3 ~ treat_w2*cert_debt_rec_w2 + as.factor(debt_pre_w2), data = debt_w2_w3)
dd_index_conc_ma_w3 <- margins::margins(dd_index_conc_w3, variables = "treat_w2", at = list(cert_debt_rec_w2 = c("Serious problem", "Uncertain", "Not a serious problem")))
ame_dd_index_conc_w3 <- as.data.frame(summary(dd_index_conc_ma_w3))
ame_dd_index_conc_w3$cert_debt_rec_w2 <- as.character(ame_dd_index_conc_w3$cert_debt_rec_w2)
ame_dd_index_conc_w3$AME <- as.numeric(ame_dd_index_conc_w3$AME)
ame_dd_index_conc_w3$SE <- as.numeric(ame_dd_index_conc_w3$SE)
ame_dd_index_conc_w3$Treatment <- ame_dd_index_conc_w3$factor
ame_dd_index_conc_w3$upper95 <- ame_dd_index_conc_w3$AME + (ame_dd_index_conc_w3$SE*1.96)
ame_dd_index_conc_w3$lower95 <- ame_dd_index_conc_w3$AME - (ame_dd_index_conc_w3$SE*1.96)

ame_dd_index_conc_w3$Treatment[ame_dd_index_conc_w3$Treatment=="treat_w22"] <- "Sustainable"
ame_dd_index_conc_w3$Treatment[ame_dd_index_conc_w3$Treatment=="treat_w23"] <- "Unsustainable"
ame_dd_index_conc_w3$Survey <- "Survey 2, Wave 2"
names(ame_dd_index_conc_w3)[names(ame_dd_index_conc_w3) == "cert_debt_rec_w2"] <- "cert_debt_rec"

# combine the three df
ame_dd_index_conc_all <- rbind(ame_dd_index_conc_w1, ame_dd_index_conc_w2)
ame_dd_index_conc_all <- rbind(ame_dd_index_conc_all, ame_dd_index_conc_w3)

# Reorder the levels of the country variable
ame_dd_index_conc_all$Survey <- factor(ame_dd_index_conc_all$Survey, levels = c("Survey 2, Wave 2", "Survey 2, Wave 1", "Survey 1"))

# focus on people who are certain that it is a certain problem
gg_ame_dd_index_conc_serious <- ggplot(ame_dd_index_conc_all[which(ame_dd_index_conc_all$cert_debt_rec=="Serious problem"),], aes(colour = Survey)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = Survey), position = position_dodge(width=0.5), size=2) +
  theme_bw() + 
      scale_color_grey("", breaks = rev(levels(ame_dd_index_conc_all$Survey)), labels = rev(levels(ame_dd_index_conc_all$Survey)), start = 0.6, end = 0.2) +
      scale_fill_grey("", breaks = rev(levels(ame_dd_index_conc_all$Survey)), labels = rev(levels(ame_dd_index_conc_all$Survey)), start = 0.6, end = 0.2) + 
      scale_shape_discrete("", breaks = rev(levels(ame_dd_index_conc_all$Survey)), labels = rev(levels(ame_dd_index_conc_all$Survey))) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.8, 0.8) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Prior = Serious Prob. & Certain") + 
      theme(plot.title = element_text(face = "bold"))

# focus on people who are uncertain
gg_ame_dd_index_conc_uncertain <- ggplot(ame_dd_index_conc_all[which(ame_dd_index_conc_all$cert_debt_rec=="Uncertain"),], aes(colour = Survey)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = Survey), position = position_dodge(width=0.5), size=2) +
  theme_bw() + 
      scale_color_grey("", breaks = rev(levels(ame_dd_index_conc_all$Survey)), labels = rev(levels(ame_dd_index_conc_all$Survey)), start = 0.6, end = 0.2) +
      scale_fill_grey("", breaks = rev(levels(ame_dd_index_conc_all$Survey)), labels = rev(levels(ame_dd_index_conc_all$Survey)), start = 0.6, end = 0.2) + 
      scale_shape_discrete("", breaks = rev(levels(ame_dd_index_conc_all$Survey)), labels = rev(levels(ame_dd_index_conc_all$Survey))) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.8, 0.8) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Uncertain") + 
      theme(plot.title = element_text(face = "bold"))
```

```{r, include = FALSE}
# analyze effect of treatment on debt index by concern for survey 1
dd_index_pre_w1 <- lm(debt_index_z_w1 ~ treat*as.factor(debt_pre_w1), data = debt_w1)
dd_index_pre_ma_w1 <- margins::margins(dd_index_pre_w1, variables = "treat", at = list(debt_pre_w1 = c("3")))
ame_dd_index_pre_w1 <- as.data.frame(summary(dd_index_pre_ma_w1))
ame_dd_index_pre_w1$AME <- as.numeric(ame_dd_index_pre_w1$AME)
ame_dd_index_pre_w1$SE <- as.numeric(ame_dd_index_pre_w1$SE)
ame_dd_index_pre_w1$Treatment <- ame_dd_index_pre_w1$factor
ame_dd_index_pre_w1$upper95 <- ame_dd_index_pre_w1$AME + (ame_dd_index_pre_w1$SE*1.96)
ame_dd_index_pre_w1$lower95 <- ame_dd_index_pre_w1$AME - (ame_dd_index_pre_w1$SE*1.96)

ame_dd_index_pre_w1$Treatment[ame_dd_index_pre_w1$Treatment=="treat2"] <- "Sustainable"
ame_dd_index_pre_w1$Treatment[ame_dd_index_pre_w1$Treatment=="treat3"] <- "Unsustainable"
ame_dd_index_pre_w1$Survey <- "Survey 1"
names(ame_dd_index_pre_w1)[names(ame_dd_index_pre_w1) == "debt_pre_w1"] <- "debt_pre"

# analyze effect of treatment on debt index by concern for survey 2
dd_index_pre_w2 <- lm(debt_index_z_w2 ~ treat*as.factor(debt_pre_w2), data = debt_w2)
dd_index_pre_ma_w2 <- margins::margins(dd_index_pre_w2, variables = "treat", at = list(debt_pre_w2 = c("3")))
ame_dd_index_pre_w2 <- as.data.frame(summary(dd_index_pre_ma_w2))
ame_dd_index_pre_w2$AME <- as.numeric(ame_dd_index_pre_w2$AME)
ame_dd_index_pre_w2$SE <- as.numeric(ame_dd_index_pre_w2$SE)
ame_dd_index_pre_w2$Treatment <- ame_dd_index_pre_w2$factor
ame_dd_index_pre_w2$upper95 <- ame_dd_index_pre_w2$AME + (ame_dd_index_pre_w2$SE*1.96)
ame_dd_index_pre_w2$lower95 <- ame_dd_index_pre_w2$AME - (ame_dd_index_pre_w2$SE*1.96)

ame_dd_index_pre_w2$Treatment[ame_dd_index_pre_w2$Treatment=="treat2"] <- "Sustainable"
ame_dd_index_pre_w2$Treatment[ame_dd_index_pre_w2$Treatment=="treat3"] <- "Unsustainable"
ame_dd_index_pre_w2$Survey <- "Survey 2, Wave 1"
names(ame_dd_index_pre_w2)[names(ame_dd_index_pre_w2) == "debt_pre_w2"] <- "debt_pre"

# analyze effect of treatment on debt index by concern for survey 2, pt 2
dd_index_pre_w3 <- lm(debt_index_z_w3 ~ treat_w2*as.factor(debt_pre_w2), data = debt_w2_w3)
dd_index_pre_ma_w3 <- margins::margins(dd_index_pre_w3, variables = "treat_w2", at = list(debt_pre_w2 = c("3")))
ame_dd_index_pre_w3 <- as.data.frame(summary(dd_index_pre_ma_w3))
ame_dd_index_pre_w3$AME <- as.numeric(ame_dd_index_pre_w3$AME)
ame_dd_index_pre_w3$SE <- as.numeric(ame_dd_index_pre_w3$SE)
ame_dd_index_pre_w3$Treatment <- ame_dd_index_pre_w3$factor
ame_dd_index_pre_w3$upper95 <- ame_dd_index_pre_w3$AME + (ame_dd_index_pre_w3$SE*1.96)
ame_dd_index_pre_w3$lower95 <- ame_dd_index_pre_w3$AME - (ame_dd_index_pre_w3$SE*1.96)

ame_dd_index_pre_w3$Treatment[ame_dd_index_pre_w3$Treatment=="treat_w22"] <- "Sustainable"
ame_dd_index_pre_w3$Treatment[ame_dd_index_pre_w3$Treatment=="treat_w23"] <- "Unsustainable"
ame_dd_index_pre_w3$Survey <- "Survey 2, Wave 2"
names(ame_dd_index_pre_w3)[names(ame_dd_index_pre_w3) == "debt_pre_w2"] <- "debt_pre"

# combine the three df
ame_dd_index_pre_all <- rbind(ame_dd_index_pre_w1, ame_dd_index_pre_w2)
ame_dd_index_pre_all <- rbind(ame_dd_index_pre_all, ame_dd_index_pre_w3)

# Reorder the levels of the country variable
ame_dd_index_pre_all$Survey <- factor(ame_dd_index_pre_all$Survey, levels = c("Survey 2, Wave 2", "Survey 2, Wave 1", "Survey 1"))

# focus on people who are certain
gg_ame_dd_index_pre <- ggplot(ame_dd_index_pre_all, aes(colour = Survey)) + 
  geom_errorbar(aes(y = Treatment, xmin=lower95, xmax=upper95), width=0, position=position_dodge(width=0.5)) + 
  geom_point(aes(y = Treatment, x=AME, shape = Survey), position = position_dodge(width=0.5), size=2) +
  theme_bw() + 
      scale_color_grey("", breaks = rev(levels(ame_dd_index_pre_all$Survey)), labels = rev(levels(ame_dd_index_pre_all$Survey)), start = 0.6, end = 0.2) +
      scale_fill_grey("", breaks = rev(levels(ame_dd_index_pre_all$Survey)), labels = rev(levels(ame_dd_index_pre_all$Survey)), start = 0.6, end = 0.2) + 
      scale_shape_discrete("", breaks = rev(levels(ame_dd_index_pre_all$Survey)), labels = rev(levels(ame_dd_index_pre_all$Survey))) +
  geom_vline(xintercept=0, color="grey", linetype = "dashed") +
      xlim(-0.8, 0.8) +
      xlab("Average treatment effect") +
      theme(legend.position="bottom") +
      theme(legend.position="bottom") + ggtitle("Prior = Somewhat a Problem") + 
      theme(plot.title = element_text(face = "bold"))
```

```{r, include = FALSE}
# save the combined graph
hte_prior <- ggarrange(gg_ame_dd_index_conc_serious,
                       gg_ame_dd_index_pre + 
                             theme(axis.text.y = element_blank(),
                                   axis.title.y = element_blank()),
                       nrow = 1,
                       common.legend = TRUE, legend = "bottom",
                       widths = c(1, 0.8))

ggsave(hte_prior, width = 18, height = 8, units = c("cm"), file ="appendix/FigureG2.pdf")
```

## Figure G.3: Self-Selection into treatment

```{r, echo=FALSE}
# recode what video they want to watch
debt_w2_w3$video_op2_w3 <- as.numeric(debt_w2_w3$video_op2_w3)
debt_w2_w3$video_op2_w3_rec <- ifelse(debt_w2_w3$video_op2_w3==1, "Unsustainable", ifelse(debt_w2_w3$video_op2_w3==2, "Sustainable", ifelse(debt_w2_w3$video_op2_w3==3, "Neither nor", NA)))
video_new_w3 <-debt_w2_w3[which(!is.na(debt_w2_w3$video_op2_w3_rec)),] %>%
  group_by(video_op2_w3_rec) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% ggplot(aes(y = freq, x=video_op2_w3_rec)) +
  geom_bar(stat="identity") +
  scale_y_continuous(limits=c(0,0.5), breaks = c(0.0, 0.2, 0.4,  0.6, 0.8, 1)) +
  ylab("Share") + xlab("Video") + theme_bw() + geom_text(aes(label = round(freq,3)),size = 3, color="white", position = position_stack(vjust = 0.5))
video_new_w3
ggsave(video_new_w3, width = 12, height = 7, units = c("cm"), file ="appendix/FigureG3.pdf")
```

## Figure G.4: Time spent watching video after self-Selection into treatment

```{r, echo=FALSE}
debt_w2_w3$time_S_video_w3 <- as.numeric(debt_w2_w3$timing_videoS_PageSubmit_w3)
debt_w2_w3$time_S_video_w3_rec <- ifelse(debt_w2_w3$time_S_video_w3<30, "Less than 30 sec", ifelse(debt_w2_w3$time_S_video_w3>=30 & debt_w2_w3$time_S_video_w3<60, "30 to 60 sec", ifelse(debt_w2_w3$time_S_video_w3>=60 & debt_w2_w3$time_S_video_w3<120, "60 to 120 sec", ifelse(debt_w2_w3$time_S_video_w3>=120 & debt_w2_w3$time_S_video_w3<180, "120 to 180 sec", ifelse(debt_w2_w3$time_S_video_w3>=180, "More than 180 sec", NA)))))
debt_w2_w3$time_US_video_w3 <- as.numeric(debt_w2_w3$timing_videoUS_PageSubmit_w3)
debt_w2_w3$time_US_video_w3_rec <- ifelse(debt_w2_w3$time_US_video_w3<30, "Less than 30 sec", ifelse(debt_w2_w3$time_US_video_w3>=30 & debt_w2_w3$time_US_video_w3<60, "30 to 60 sec", ifelse(debt_w2_w3$time_US_video_w3>=60 & debt_w2_w3$time_US_video_w3<120, "60 to 120 sec", ifelse(debt_w2_w3$time_US_video_w3>=120 & debt_w2_w3$time_US_video_w3<180, "120 to 180 sec", ifelse(debt_w2_w3$time_US_video_w3>=180, "More than 180 sec", NA)))))
debt_w2_w3$video_time <- ifelse(is.na(debt_w2_w3$time_S_video_w3_rec), debt_w2_w3$time_US_video_w3_rec ,debt_w2_w3$time_S_video_w3_rec)
debt_w2_w3$video_time <- factor(debt_w2_w3$video_time, levels=c("Less than 30 sec", "30 to 60 sec", "60 to 120 sec", "120 to 180 sec", "More than 180 sec"))
debt_w2_w3$video_choice <- ifelse(!is.na(debt_w2_w3$time_S_video_w3_rec), "Sustainable", ifelse(!is.na(debt_w2_w3$time_US_video_w3_rec), "Unsustainable", NA))
video_time <-debt_w2_w3[which(!is.na(debt_w2_w3$video_choice)),] %>%
  group_by(video_choice, video_time) %>%
  summarise(n = n()) %>%
  mutate(freq = n / sum(n)) %>% ggplot(aes(y = freq, x=video_time)) +
  geom_bar(stat="identity")+ facet_wrap(video_choice ~ .) +
  ylab("Share") + xlab("Time spent watching the video")  +  theme_bw() + theme(axis.text.x = element_text(angle = 45, vjust = 1.2,hjust=1.2)) + geom_text(aes(label = round(freq,3)),size = 3, color="white", position = position_stack(vjust = 0.5))
video_time
ggsave(video_time, width = 15, height = 7, units = c("cm"), file ="appendix/FigureG4.pdf")
```
